#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
#define eps 1e-10
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 2e3 + 5;
const string NAME = "escaping";
int n, m, w, h;
int p[N], ans[100001];
vector<tuple<int, int, int>> queries;
vector<tuple<long double, int, int>> edges;
int find_set(int u){
if(u == p[u])
return u;
return p[u] = find_set(p[u]);
}
void join_set(int u, int v){
u = find_set(u);
v = find_set(v);
if(u == v)
return;
p[v] = u;
}
struct circ{
long double x, y, r;
circ(long double _x = 0, long double _y = 0, long double _r = 0) : x(_x), y(_y), r(_r) {}
} a[N];
long double dis(int i, int j){
long double gg = 1.0 * (a[i].x - a[j].x) * (a[i].x - a[j].x) + 1.0 * (a[i].y - a[j].y) * (a[i].y - a[j].y);
gg = sqrtl(gg);
gg -= 1.0 * (a[i].r + a[j].r);
if(gg < eps)
gg = 0;
return gg;
}
bool ok(int i, int j){
return find_set(i) != find_set(j);
}
bool check(int i, int j){
if(i == j)
return true;
if(i > j)
swap(i, j);
if(i == 1 && j == 2)
return (ok(n + 1, n + 2) && ok(n + 1, n + 3) && ok(n + 1, n + 4));
if(i == 1 && j == 3)
return (ok(n + 1, n + 3) && ok(n + 1, n + 4) && ok(n + 2, n + 3) && ok(n + 2, n + 4));
if(i == 1 && j == 4)
return (ok(n + 1, n + 4) && ok(n + 2, n + 4) && ok(n + 3, n + 4));
if(i == 2 && j == 3)
return (ok(n + 1, n + 2) && ok(n + 2, n + 3) && ok(n + 2, n + 4));
if(i == 2 && j == 4)
return (ok(n + 1, n + 2) && ok(n + 1, n + 3) && ok(n + 2, n + 4) && ok(n + 3, n + 4));
return (ok(n + 1, n + 3) && ok(n + 2, n + 3) && ok(n + 3, n + 4));
}
void inp(){
cin >> n >> m >> w >> h;
for(int i = 1; i <= n; ++i){
int x, y, r;
cin >> x >> y >> r;
a[i] = circ(x, y, r);
}
for(int i = 1; i <= m; ++i){
int r, e;
cin >> r >> e;
queries.pb({r, e, i});
}
}
void solve(){
for(int i = 1; i <= n; ++i)
for(int j = i + 1; j <= n; ++j){
long double W = dis(i, j);
edges.pb({W, i, j});
}
for(int i = 1; i <= n; ++i){
long double W = (a[i].y <= a[i].r ? 0 : a[i].y - a[i].r);
edges.pb({W, i, n + 1});
}
for(int i = 1; i <= n; ++i){
long double W = (w - a[i].x <= a[i].r ? 0 : w - a[i].x - a[i].r);
edges.pb({W, i, n + 2});
}
for(int i = 1; i <= n; ++i){
long double W = (h - a[i].y <= a[i].r ? 0 : h - a[i].y - a[i].r);
edges.pb({W, i, n + 3});
}
for(int i = 1; i <= n; ++i){
long double W = (a[i].x <= a[i].r ? 0 : a[i].x - a[i].r);
edges.pb({W, i, n + 4});
}
sort(edges.begin(), edges.end());
sort(queries.begin(), queries.end());
for(int i = 1; i <= n + 4; ++i)
p[i] = i;
int ptr = 0;
for(auto [r, e, i] : queries){
while(ptr < edges.size()){
auto [W, u, v] = edges[ptr];
if(W - 2.0 * r > eps)
break;
join_set(u, v);
++ptr;
}
for(int j = 1; j <= 4; ++j)
if(check(e, j))
ans[i] |= (1 << j);
}
for(int i = 1; i <= m; ++i){
for(int j = 1; j <= 4; ++j)
if((ans[i] >> j) & 1)
cout << j;
cout << "\n";
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen((NAME + ".inp").c_str(), "r")){
freopen((NAME + ".inp").c_str(), "r", stdin);
freopen((NAME + ".out").c_str(), "w", stdout);
}
inp();
solve();
}
Compilation message
park.cpp: In function 'void solve()':
park.cpp:140:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<long double, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | while(ptr < edges.size()){
| ~~~~^~~~~~~~~~~~~~
park.cpp: In function 'int main()':
park.cpp:168:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
168 | freopen((NAME + ".inp").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:169:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
169 | freopen((NAME + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
411 ms |
68272 KB |
Output is correct |
2 |
Correct |
404 ms |
68260 KB |
Output is correct |
3 |
Correct |
407 ms |
68292 KB |
Output is correct |
4 |
Correct |
409 ms |
68280 KB |
Output is correct |
5 |
Correct |
407 ms |
68272 KB |
Output is correct |
6 |
Correct |
408 ms |
68324 KB |
Output is correct |
7 |
Correct |
373 ms |
68264 KB |
Output is correct |
8 |
Incorrect |
375 ms |
68332 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
4032 KB |
Output is correct |
2 |
Correct |
45 ms |
4028 KB |
Output is correct |
3 |
Correct |
36 ms |
4036 KB |
Output is correct |
4 |
Correct |
35 ms |
4032 KB |
Output is correct |
5 |
Correct |
35 ms |
4040 KB |
Output is correct |
6 |
Incorrect |
37 ms |
4072 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
411 ms |
68272 KB |
Output is correct |
2 |
Correct |
404 ms |
68260 KB |
Output is correct |
3 |
Correct |
407 ms |
68292 KB |
Output is correct |
4 |
Correct |
409 ms |
68280 KB |
Output is correct |
5 |
Correct |
407 ms |
68272 KB |
Output is correct |
6 |
Correct |
408 ms |
68324 KB |
Output is correct |
7 |
Correct |
373 ms |
68264 KB |
Output is correct |
8 |
Incorrect |
375 ms |
68332 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |