Submission #71324651


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define debug(arg) cout << "[" << #arg << "]: " << arg << endl
#else
#define debug(arg) 42
#endif

using llu = unsigned long long;
using ll = long long;

#define vec vector
#define pb push_back
#define all(n) begin(n), end(n)

void solv() {
	int n; cin >> n;
	vec<pair<int, int>> xr(n);
	for (auto &[x, r] : xr) cin >> x >> r;
	vec<int> vals;
	for (auto &[x, r] : xr) vals.pb(x - r), vals.pb(x + r);
	sort(all(vals)), vals.erase(unique(all(vals)), vals.end());
	n = vals.size();
	vec<vec<int>> adj(n);
	for (auto &[x, r] : xr) {
		int u = lower_bound(all(vals), x - r) - vals.begin();
		int v = lower_bound(all(vals), x + r) - vals.begin();
		adj[u].pb(v);
		adj[v].pb(u);
	}
	vec<bool> vis(n);
	auto dfs = [&](auto &&dfs, int u, int p = -1) -> bool {
		if (vis[u]) return true;
		vis[u] = true;
		bool res = false;
		for (auto &v : adj[u]) if (v != p) res |= dfs(dfs, v, u);
		return res;
	};
	int ans = 0;
	debug(n);
	for (int i = 0; i < n; ++i) ans += dfs(dfs, i);
	cout << ans << '\n';
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while (t--) solv();
	return 0;
}

Submission Info

Submission Time
Task E - Distribute Bunnies
User fisher199
Language C++23 (Clang 21.1.0)
Score 500
Code Size 1227 Byte
Status AC
Exec Time 232 ms
Memory 29416 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 42
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 02_small_cc_00.txt, 02_small_cc_01.txt, 02_small_cc_02.txt, 02_small_cc_03.txt, 02_small_cc_04.txt, 02_small_cc_05.txt, 02_small_cc_06.txt, 02_small_cc_07.txt, 02_small_cc_08.txt, 02_small_cc_09.txt, 02_small_cc_10.txt, 02_small_cc_11.txt, 02_small_cc_12.txt, 02_small_cc_13.txt, 02_small_cc_14.txt, 02_small_cc_15.txt, 02_small_cc_16.txt, 02_small_cc_17.txt, 02_small_cc_18.txt, 02_small_cc_19.txt, 03_path_00.txt, 03_path_01.txt, 04_cycle_00.txt, 04_cycle_01.txt, 05_namori_00.txt, 05_namori_01.txt, 05_namori_02.txt, 05_namori_03.txt, 05_namori_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3000 KiB
00_sample_01.txt AC 1 ms 3024 KiB
00_sample_02.txt AC 1 ms 2980 KiB
01_random_00.txt AC 161 ms 21384 KiB
01_random_01.txt AC 200 ms 18416 KiB
01_random_02.txt AC 171 ms 23052 KiB
01_random_03.txt AC 208 ms 27696 KiB
01_random_04.txt AC 154 ms 20800 KiB
01_random_05.txt AC 219 ms 27264 KiB
01_random_06.txt AC 123 ms 16352 KiB
01_random_07.txt AC 200 ms 25712 KiB
01_random_08.txt AC 124 ms 16832 KiB
01_random_09.txt AC 187 ms 16768 KiB
02_small_cc_00.txt AC 145 ms 27916 KiB
02_small_cc_01.txt AC 149 ms 27140 KiB
02_small_cc_02.txt AC 151 ms 26352 KiB
02_small_cc_03.txt AC 152 ms 25576 KiB
02_small_cc_04.txt AC 153 ms 25052 KiB
02_small_cc_05.txt AC 153 ms 24408 KiB
02_small_cc_06.txt AC 152 ms 23900 KiB
02_small_cc_07.txt AC 154 ms 23384 KiB
02_small_cc_08.txt AC 156 ms 22712 KiB
02_small_cc_09.txt AC 153 ms 22380 KiB
02_small_cc_10.txt AC 154 ms 21864 KiB
02_small_cc_11.txt AC 154 ms 21476 KiB
02_small_cc_12.txt AC 153 ms 21108 KiB
02_small_cc_13.txt AC 153 ms 20700 KiB
02_small_cc_14.txt AC 153 ms 20332 KiB
02_small_cc_15.txt AC 152 ms 19932 KiB
02_small_cc_16.txt AC 153 ms 19756 KiB
02_small_cc_17.txt AC 152 ms 19328 KiB
02_small_cc_18.txt AC 152 ms 18940 KiB
02_small_cc_19.txt AC 152 ms 18648 KiB
03_path_00.txt AC 163 ms 29404 KiB
03_path_01.txt AC 226 ms 24588 KiB
04_cycle_00.txt AC 164 ms 29416 KiB
04_cycle_01.txt AC 225 ms 29404 KiB
05_namori_00.txt AC 231 ms 17168 KiB
05_namori_01.txt AC 231 ms 17080 KiB
05_namori_02.txt AC 230 ms 17124 KiB
05_namori_03.txt AC 226 ms 22432 KiB
05_namori_04.txt AC 232 ms 17136 KiB