#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2005;
long long X[MAX_N], Y[MAX_N], R[MAX_N];
long long dist[MAX_N][MAX_N];
long long wall[5][5];
int parent[MAX_N];
int find_parent(int u) {
if(u == parent[u]) {
return u;
}
return parent[u] = find_parent(parent[u]);
}
void merge(int u, int v) {
u = find_parent(u), v = find_parent(v);
if(u == v) {
return;
}
parent[v] = u;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M, W, H;
cin >> N >> M >> W >> H;
for(int i = 0; i < N; i++) {
cin >> X[i] >> Y[i] >> R[i];
}
vector <tuple <long long, int, int>> edges;
for(int i = 0; i < N; i++) {
for(int j = i + 1; j < N; j++) {
dist[i][j] = sqrt((X[i] - X[j]) * (X[i] - X[j]) + (Y[i] - Y[j]) * (Y[i] - Y[j])) - R[i] - R[j];
}
}
for(int i = 0; i < N; i++) {
dist[i][N + 3] = H - Y[i] - R[i];
dist[i][N + 2] = W - X[i] - R[i];
dist[i][N + 1] = Y[i] - R[i];
dist[i][N + 0] = X[i] - R[i];
}
for(int i = 0; i < N; i++) {
for(int j = i + 1; j < N + 4; j++) {
edges.emplace_back(dist[i][j], i, j);
}
}
sort(edges.begin(), edges.end());
for(int i = 0; i < N + 4; i++) {
parent[i] = i;
}
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
wall[i][j] = -1;
}
}
for(auto [d, u, v] : edges) {
merge(u, v);
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
if(i == j or wall[i][j] != -1) {
continue;
}
if(find_parent(N + i) == find_parent(N + j)) {
wall[i][j] = d;
}
}
}
}
while(M--) {
int r, e;
cin >> r >> e;
e--;
for(int i = 0; i < 4; i++) {
bool ok = true;
if(i != e) {
ok &= (wall[(i + 1) % 4][i] >= 2 * r);
ok &= (wall[(e + 1) % 4][e] >= 2 * r);
if((4 + i - e) % 4 >= 2) {
ok &= (wall[e][(e + 2) % 4] >= 2 * r);
}
if((4 + i - e) % 4 <= 2) {
ok &= (wall[(e + 1) % 4][(e + 3) % 4] >= 2 * r);
}
}
if(ok == true) {
cout << i + 1;
}
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
270 ms |
55996 KB |
Output is correct |
2 |
Correct |
266 ms |
56036 KB |
Output is correct |
3 |
Correct |
276 ms |
55980 KB |
Output is correct |
4 |
Correct |
267 ms |
56084 KB |
Output is correct |
5 |
Correct |
273 ms |
56092 KB |
Output is correct |
6 |
Correct |
264 ms |
56060 KB |
Output is correct |
7 |
Correct |
306 ms |
55992 KB |
Output is correct |
8 |
Correct |
276 ms |
56020 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
2104 KB |
Output is correct |
2 |
Correct |
32 ms |
2012 KB |
Output is correct |
3 |
Correct |
33 ms |
2024 KB |
Output is correct |
4 |
Correct |
40 ms |
2032 KB |
Output is correct |
5 |
Correct |
40 ms |
2016 KB |
Output is correct |
6 |
Correct |
43 ms |
2184 KB |
Output is correct |
7 |
Correct |
29 ms |
588 KB |
Output is correct |
8 |
Correct |
28 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
270 ms |
55996 KB |
Output is correct |
2 |
Correct |
266 ms |
56036 KB |
Output is correct |
3 |
Correct |
276 ms |
55980 KB |
Output is correct |
4 |
Correct |
267 ms |
56084 KB |
Output is correct |
5 |
Correct |
273 ms |
56092 KB |
Output is correct |
6 |
Correct |
264 ms |
56060 KB |
Output is correct |
7 |
Correct |
306 ms |
55992 KB |
Output is correct |
8 |
Correct |
276 ms |
56020 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
34 ms |
2104 KB |
Output is correct |
12 |
Correct |
32 ms |
2012 KB |
Output is correct |
13 |
Correct |
33 ms |
2024 KB |
Output is correct |
14 |
Correct |
40 ms |
2032 KB |
Output is correct |
15 |
Correct |
40 ms |
2016 KB |
Output is correct |
16 |
Correct |
43 ms |
2184 KB |
Output is correct |
17 |
Correct |
29 ms |
588 KB |
Output is correct |
18 |
Correct |
28 ms |
624 KB |
Output is correct |
19 |
Correct |
297 ms |
55988 KB |
Output is correct |
20 |
Correct |
308 ms |
56160 KB |
Output is correct |
21 |
Correct |
300 ms |
56040 KB |
Output is correct |
22 |
Correct |
298 ms |
55992 KB |
Output is correct |
23 |
Correct |
297 ms |
55976 KB |
Output is correct |
24 |
Correct |
323 ms |
55984 KB |
Output is correct |