#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
const int MOD = 1e9+7;
#define F first
#define S second
#define PB push_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
void FASTIO() {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
const int MXN = 2005;
const int MXM = 1e5+5;
int n, m;
ll w, h;
ll X[MXN], Y[MXN], R[MXN];
double dist[MXN][MXN];
vector<pii> edges;
// n - down, n+1 - right, n+2 - up, n+3 - left
double connected_at[4][4];
// dsu
int par[MXN], sz[MXN];
void init() {
iota(par, par+n+4, 0);
fill(sz, sz+n+4, 1);
}
int find_set(int a) {
return par[a] == a ? a : par[a] = find_set(par[a]);
}
void unite(int a, int b) {
a = find_set(a), b = find_set(b);
if(a == b) return;
if(sz[a] < sz[b]) swap(a, b);
par[b] = a;
sz[a] += sz[b];
}
//
int main() {
FASTIO();
cin >> n >> m;
cin >> w >> h;
for(int i = 0; i < n; i++) {
cin >> X[i] >> Y[i] >> R[i];
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < i; j++) {
dist[i][j] = sqrt(1.0*(X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]))-R[i]-R[j];
edges.PB({i, j});
}
dist[i][n] = Y[i] - R[i];
dist[i][n+1] = (w - X[i]) - R[i];
dist[i][n+2] = (h - Y[i]) - R[i];
dist[i][n+3] = X[i] - R[i];
edges.PB({i, n});
edges.PB({i, n+1});
edges.PB({i, n+2});
edges.PB({i, n+3});
}
sort(all(edges), [&](pii a, pii b){
return dist[a.F][a.S] < dist[b.F][b.S];
});
init();
for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) connected_at[i][j] = w*h;
for(auto e : edges) {
unite(e.F, e.S);
double d = dist[e.F][e.S];
for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) {
if(find_set(n+i) == find_set(n+j)) {
connected_at[i][j] = min(connected_at[i][j], d);
}
}
}
// for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) {
// cerr << i << " " << j << ": " << fixed << setprecision(0) << connected_at[i][j] << "\n";
// }
for(int i = 0; i < m; i++) {
ll r, e; cin >> r >> e; e--;
for(int j = 0; j < 4; j++) {
bool ok = true;
ok &= connected_at[e][(e+3)%4]+1e-3 >= 2*r;
ok &= connected_at[j][(j+3)%4]+1e-3 >= 2*r;
if((j+2)%4 == e) {
// opposite
ok &= connected_at[j][(j+2)%4]+1e-3 >= 2*r;
ok &= connected_at[(j+1)%4][(j+3)%4]+1e-3 >= 2*r;
}
else if((j+1)%4 == e) {
ok &= connected_at[j][(j+2)%4]+1e-3 >= 2*r;
}
else {
ok &= connected_at[e][(e+2)%4]+1e-3 >= 2*r;
}
if(j == e) ok = true;
if(ok) {
cout << j+1;
}
}
cout << "\n";
}
return 0;
}
/*
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
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
700 ms |
38932 KB |
Output is correct |
2 |
Correct |
799 ms |
38980 KB |
Output is correct |
3 |
Correct |
727 ms |
39008 KB |
Output is correct |
4 |
Correct |
746 ms |
38928 KB |
Output is correct |
5 |
Correct |
815 ms |
38936 KB |
Output is correct |
6 |
Correct |
724 ms |
38932 KB |
Output is correct |
7 |
Correct |
458 ms |
38968 KB |
Output is correct |
8 |
Correct |
477 ms |
38928 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
2160 KB |
Output is correct |
2 |
Correct |
41 ms |
2108 KB |
Output is correct |
3 |
Correct |
43 ms |
2068 KB |
Output is correct |
4 |
Correct |
35 ms |
2012 KB |
Output is correct |
5 |
Correct |
37 ms |
2084 KB |
Output is correct |
6 |
Correct |
37 ms |
2100 KB |
Output is correct |
7 |
Correct |
31 ms |
636 KB |
Output is correct |
8 |
Correct |
32 ms |
1748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
700 ms |
38932 KB |
Output is correct |
2 |
Correct |
799 ms |
38980 KB |
Output is correct |
3 |
Correct |
727 ms |
39008 KB |
Output is correct |
4 |
Correct |
746 ms |
38928 KB |
Output is correct |
5 |
Correct |
815 ms |
38936 KB |
Output is correct |
6 |
Correct |
724 ms |
38932 KB |
Output is correct |
7 |
Correct |
458 ms |
38968 KB |
Output is correct |
8 |
Correct |
477 ms |
38928 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
50 ms |
2160 KB |
Output is correct |
12 |
Correct |
41 ms |
2108 KB |
Output is correct |
13 |
Correct |
43 ms |
2068 KB |
Output is correct |
14 |
Correct |
35 ms |
2012 KB |
Output is correct |
15 |
Correct |
37 ms |
2084 KB |
Output is correct |
16 |
Correct |
37 ms |
2100 KB |
Output is correct |
17 |
Correct |
31 ms |
636 KB |
Output is correct |
18 |
Correct |
32 ms |
1748 KB |
Output is correct |
19 |
Correct |
777 ms |
40312 KB |
Output is correct |
20 |
Correct |
741 ms |
40232 KB |
Output is correct |
21 |
Correct |
751 ms |
40340 KB |
Output is correct |
22 |
Correct |
789 ms |
40328 KB |
Output is correct |
23 |
Correct |
752 ms |
40216 KB |
Output is correct |
24 |
Correct |
488 ms |
40344 KB |
Output is correct |