#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010
bool can[4][4];
#define maxn 2000
bool wallTop[maxn], wallBot[maxn], wallLeft[maxn], wallRight[maxn];
struct object {
int x, y, r;
};
void updCan(int i) {
//cout << i << endl;
if (wallTop[i] && wallBot[i]) {
//cout << "top & bot" << endl;
can[0][1] = can[0][2] = can[3][1] = can[3][2] = can[1][0] = can[2][0] = can[1][3] = can[2][3] = 0;
}
if (wallTop[i] && wallLeft[i]) {
//cout << "top & left" << endl;
can[3][0] = can[3][1] = can[3][2] = can[0][3] = can[1][3] = can[2][3] = 0;
}
if (wallTop[i] && wallRight[i]) {
//cout << "top & right" << endl;
can[2][0] = can[2][1] = can[2][3] = can[0][2] = can[1][2] = can[3][2] = 0;
}
if (wallLeft[i] && wallRight[i]) {
//cout << "left & right" << endl;
can[2][0] = can[2][1] = can[0][2] = can[1][2] = can[0][3] = can[1][3] = can[3][1] = can[3][0] = 0;
}
if (wallLeft[i] && wallBot[i]) {
//cout << "left & bot" << endl;
can[0][3] = can[0][1] = can[0][2] = can[2][0] = can[1][0] = can[3][0] = 0;
}
if (wallRight[i] && wallBot[i]) {
//cout << "right & bot" << endl;
can[1][0] = can[1][3] = can[1][2] = can[0][1] = can[3][1] = can[2][1] = 0;
}
}
int pa[maxn], sz[maxn];
int get(int x) {
return pa[x] == x ? x : pa[x] = get(pa[x]);
}
void unite(int a, int b) {
a = get(a), b = get(b);
if (a == b) return;
if (sz[a] > sz[b]) swap(a, b);
sz[b] += sz[a];
pa[a] = b;
wallTop[b] = wallTop[b] || wallTop[a];
wallBot[b] = wallBot[b] || wallBot[a];
wallLeft[b] = wallLeft[b] || wallLeft[a];
wallRight[b] = wallRight[b] || wallRight[a];
updCan(b);
}
vector<object> objects;
ll getDist(int i, int j) {
ll dx = abs(objects[i].x-objects[j].x);
ll dy = abs(objects[i].y-objects[j].y);
return dx*dx+dy*dy;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m, w, h; cin >> n >> m >> w >> h;
assert(m == 1);
F0R(i, 4) F0R(j, 4) can[i][j] = true;
F0R(i, n) {
int x, y, r; cin >> x >> y >> r;
objects.pb({x,y,r});
}
F0R(i, n) {
sz[i] = 1;
pa[i] = i;
}
int r, e; cin >> r >> e; --e;
F0R(i, n) {
if (objects[i].y-objects[i].r < 2*r) {
wallBot[get(i)] = true;
}
if (h-objects[i].y-objects[i].r < 2*r) {
wallTop[get(i)] = true;
}
if (objects[i].x-objects[i].r < 2*r) {
wallLeft[get(i)] = true;
}
if (w-objects[i].x-objects[i].r < 2*r) {
wallRight[get(i)] = true;
}
updCan(get(i));
}
F0R(i, n) {
FOR(j, i+1, n) {
ll r2 = (ll)2*r + objects[i].r + objects[j].r;
//cout << i << " " << j << " " << getDist(i, j) << " " << r2*r2 << endl;
if (getDist(i, j) < r2*r2) {
unite(i, j);
}
}
}
F0R(i, 4) {
if (can[e][i]) cout << i+1;
}
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
620 KB |
Output is correct |
5 |
Correct |
9 ms |
492 KB |
Output is correct |
6 |
Correct |
9 ms |
492 KB |
Output is correct |
7 |
Correct |
23 ms |
492 KB |
Output is correct |
8 |
Correct |
9 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
364 KB |
Output is correct |
2 |
Correct |
9 ms |
364 KB |
Output is correct |
3 |
Correct |
9 ms |
364 KB |
Output is correct |
4 |
Correct |
9 ms |
620 KB |
Output is correct |
5 |
Correct |
9 ms |
492 KB |
Output is correct |
6 |
Correct |
9 ms |
492 KB |
Output is correct |
7 |
Correct |
23 ms |
492 KB |
Output is correct |
8 |
Correct |
9 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Runtime error |
1 ms |
512 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |