This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |