#include <bits/stdc++.h>
using namespace std;
#define popcount(n) (__builtin_popcountll((n)))
#define clz(n) (__builtin_clzll((n)))
#define ctz(n) (__builtin_ctzll((n)))
#define lg(n) (63 - __builtin_clzll((n)))
#define BIT(n, i) (((n) >> (i)) & 1ll)
#define MASK(i) (1ll << (i))
#define FLIP(n, i) ((n) ^ (1ll << (i)))
#define ON(n, i) ((n) | MASK(i))
#define OFF(n, i) ((n) & ~MASK(i))
#define Int __int128
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vll;
typedef vector<pair<long long, int>> vli;
typedef vector<pair<int, long long>> vil;
template <class T1, class T2>
bool maximize(T1 &x, T2 y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <class T1, class T2>
bool minimize(T1 &x, T2 y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <class T>
void remove_duplicate(vector<T> &ve) {
sort (ve.begin(), ve.end());
ve.resize(unique(ve.begin(), ve.end()) - ve.begin());
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class T> T random(T l, T r) {
return uniform_int_distribution<T>(l, r)(rng);
}
template <class T> T random(T r) {
return rng() % r;
}
const int N = 2000 + 5, M = 1e5 + 5;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const vii TNK[3] = {
{{0, 0}, {2, 0}, {3, 0}},
{{0, 0}, {2, 2}, {0, 1}, {3, 0}},
{{0, 0}, {0, 2}, {0, 1}}
};
int n, m, w, h;
int ans[M];
struct Circle {
int x, y, r;
Circle(int _x = 0, int _y = 0, int _r = 0) {
x = _x, y = _y, r = _r;
}
} a[N];
struct Info {
int dist, u, v;
Info(int _dist = 0, int _u = 0, int _v = 0) {
dist = _dist, u = _u, v = _v;
}
};
vector<Info> all;
ll square(int x) {
return 1ll * x * x;
}
int floor_dist(Circle A, Circle B) {
return sqrt(square(A.x - B.x) + square(A.y - B.y)) - A.r - B.r;
}
struct DSU {
vector<int> lab;
DSU() {}
void resize(int n) {
lab.assign(n + 1, -1);
}
int find_set(int p) {
return lab[p] < 0 ? p : lab[p] = find_set(lab[p]);
}
bool same_set(int u, int v) {
return find_set(u) == find_set(v);
}
bool join(int u, int v) {
u = find_set(u), v = find_set(v);
if (u != v) {
if (lab[u] > lab[v]) swap(u, v);
lab[u] += lab[v], lab[v] = u;
return true;
}
return false;
}
} dsu;
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
cin >> n >> m >> w >> h;
for (int i = 0; i < n; ++i) {
cin >> a[i].x >> a[i].y >> a[i].r;
}
dsu.resize(n + 3);
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
all.emplace_back(floor_dist(a[i], a[j]), i, j);
}
all.emplace_back(floor_dist(a[i], Circle(0, a[i].y, 0)), i, n);
all.emplace_back(floor_dist(a[i], Circle(a[i].x, 0, 0)), i, n + 1);
all.emplace_back(floor_dist(a[i], Circle(w, a[i].y, 0)), i, n + 2);
all.emplace_back(floor_dist(a[i], Circle(a[i].x, h, 0)), i, n + 3);
}
for (int i = 1; i <= m; ++i) {
int r, e; cin >> r >> e; --e;
all.emplace_back(2 * r, e, -i);
}
sort (all.begin(), all.end(), [&](const Info &x, const Info &y) {
if (x.dist == y.dist) return x.v < y.v;
return x.dist < y.dist;
});
for (auto it : all) {
// cerr << it.dist << ' ' << it.u << ' ' << it.v << '\n';
if (it.v < 0) {
int e = it.u, id = -it.v; ans[id] = MASK(4) - 1;
// cerr << id << '\n';
for (int i = 0; i < 3; ++i) {
for (auto bruh : TNK[i]) {
int x = (e + bruh.fi) % 4, y = (e + 1 + bruh.se) % 4;
// cout << e << ' ' << i << ' ' << x << ' ' << y << '\n';
if (dsu.same_set(n + x, n + y)) ans[id] = OFF(ans[id], (e + i + 1) % 4);
}
}
}
else dsu.join(it.u, it.v);
}
for (int i = 1; i <= m; ++i) {
for (int j = 0; j < 4; ++j) if (BIT(ans[i], j)) {
cout << j + 1;
}
cout << '\n';
}
cerr << '\n'; return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
218 ms |
25280 KB |
Output is correct |
2 |
Correct |
197 ms |
25280 KB |
Output is correct |
3 |
Correct |
189 ms |
25284 KB |
Output is correct |
4 |
Correct |
192 ms |
25284 KB |
Output is correct |
5 |
Correct |
193 ms |
25280 KB |
Output is correct |
6 |
Correct |
193 ms |
25280 KB |
Output is correct |
7 |
Correct |
167 ms |
25284 KB |
Output is correct |
8 |
Correct |
169 ms |
25284 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
3608 KB |
Output is correct |
2 |
Correct |
34 ms |
3612 KB |
Output is correct |
3 |
Correct |
33 ms |
3528 KB |
Output is correct |
4 |
Correct |
34 ms |
3596 KB |
Output is correct |
5 |
Correct |
35 ms |
3780 KB |
Output is correct |
6 |
Correct |
39 ms |
3796 KB |
Output is correct |
7 |
Correct |
33 ms |
3524 KB |
Output is correct |
8 |
Correct |
32 ms |
3524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
218 ms |
25280 KB |
Output is correct |
2 |
Correct |
197 ms |
25280 KB |
Output is correct |
3 |
Correct |
189 ms |
25284 KB |
Output is correct |
4 |
Correct |
192 ms |
25284 KB |
Output is correct |
5 |
Correct |
193 ms |
25280 KB |
Output is correct |
6 |
Correct |
193 ms |
25280 KB |
Output is correct |
7 |
Correct |
167 ms |
25284 KB |
Output is correct |
8 |
Correct |
169 ms |
25284 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
36 ms |
3608 KB |
Output is correct |
12 |
Correct |
34 ms |
3612 KB |
Output is correct |
13 |
Correct |
33 ms |
3528 KB |
Output is correct |
14 |
Correct |
34 ms |
3596 KB |
Output is correct |
15 |
Correct |
35 ms |
3780 KB |
Output is correct |
16 |
Correct |
39 ms |
3796 KB |
Output is correct |
17 |
Correct |
33 ms |
3524 KB |
Output is correct |
18 |
Correct |
32 ms |
3524 KB |
Output is correct |
19 |
Correct |
254 ms |
50820 KB |
Output is correct |
20 |
Correct |
249 ms |
50820 KB |
Output is correct |
21 |
Correct |
244 ms |
50820 KB |
Output is correct |
22 |
Correct |
241 ms |
50880 KB |
Output is correct |
23 |
Correct |
240 ms |
50820 KB |
Output is correct |
24 |
Correct |
225 ms |
50860 KB |
Output is correct |