#include <bits/stdc++.h>
using namespace std;
const int kN = 2e3;
const int kM = 1e5;
int Edist(int x1, int y1, int x2, int y2) {
return sqrtl((int64_t)(x1 - x2) * (x1 - x2) + (int64_t)(y1 - y2) * (y1 - y2));
}
struct circle_t {
int x, y, r;
void read() {
cin >> x >> y >> r;
}
int dist(const circle_t &other) {
return Edist(x, y, other.x, other.y) - r - other.r;
}
} t[kN];
struct query_t {
int r, e, index;
void read() {
cin >> r >> e;
r *= 2;
e -= 1;
}
bool operator < (const query_t &rhs) const {
return r < rhs.r;
}
} q[kM];
struct edge {
int u, v, w;
bool operator < (const edge &rhs) const {
return w < rhs.w;
}
};
struct DSU {
vector<int> p, sz;
void init(int n) {
p.resize(n);
iota(p.begin(), p.end(), 0);
sz.assign(n, 1);
}
int root(int x) {
if (x == p[x]) {
return x;
}
return p[x] = root(p[x]);
}
bool connected(int x, int y) {
return root(x) == root(y);
}
bool unite(int u, int v) {
int x = root(u), y = root(v);
if (x == y) {
return false;
}
if (sz[y] < sz[x]) {
swap(x, y);
}
p[x] = y;
sz[y] += sz[x];
return true;
}
} dsu;
int n;
short sol[kM];
void solveQuery(int p) {
int e = q[p].e, index = q[p].index;
sol[index] |= (1 << e);
if (!dsu.connected(n + e, n + (e + 2) % 4) && !dsu.connected(n + e, n + (e + 3) % 4) && !dsu.connected(n + e, n + (e + 1) % 4)) {
sol[index] |= (1 << ((e + 1) % 4));
}
if (!dsu.connected(n + e, n + (e + 3) % 4) && !dsu.connected(n + (e + 1) % 4, n + (e + 2) % 4) && !dsu.connected(n + e, n + (e + 2) % 4) && !dsu.connected(n + (e + 1) % 4, n + (e + 3) % 4)) {
sol[index] |= (1 << ((e + 2) % 4));
}
if (!dsu.connected(n + e, n + (e + 3) % 4) && !dsu.connected(n + (e + 2) % 4, n + (e + 3) % 4) && !dsu.connected(n + (e + 1) % 4, n + (e + 3) % 4)) {
sol[index] |= (1 << ((e + 3) % 4));
}
}
/*
5 3
16 11
11 8 1
6 10 1
7 3 2
10 4 1
15 5 1
1 1
2 2
2 1
*/
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int m, w, h;
cin >> n >> m >> w >> h;
for (int i = 0; i < n; ++i) {
t[i].read();
}
for (int i = 0; i < m; ++i) {
q[i].read();
q[i].index = i;
}
vector<edge> edges;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
edges.push_back({i, j, t[i].dist(t[j])});
}
int x = t[i].x, y = t[i].y;
edges.push_back({i, n, Edist(x, y, x, 0)});
edges.push_back({i, n + 1, Edist(x, y, w, y)});
edges.push_back({i, n + 2, Edist(x, y, x, h)});
edges.push_back({i, n + 3, Edist(x, y, 0, y)});
}
sort(edges.begin(), edges.end());
sort(q, q + m);
dsu.init(n + 4);
int ptr = 0;
for (auto e : edges) {
while (ptr < m && q[ptr].r <= e.w) {
solveQuery(ptr);
ptr += 1;
}
dsu.unite(e.u, e.v);
}
while (ptr < m) {
solveQuery(ptr);
ptr += 1;
}
for (int i = 0; i < m; ++i) {
for (int j = 0; j < 4; ++j) {
if (sol[i] & (1 << j)) {
cout << j + 1;
}
}
cout << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
216 ms |
25176 KB |
Output is correct |
2 |
Incorrect |
218 ms |
25148 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
57 ms |
3528 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
216 ms |
25176 KB |
Output is correct |
2 |
Incorrect |
218 ms |
25148 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |