#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(x) x.begin(), x.end()
#define ms(x, a) memset(x, a, sizeof(x))
//==================================
const int MAX = 2023;
ll x[MAX], y[MAX], r[MAX], p[MAX], gone[5][5];
struct E{ int a, b; ll w; };
int findP(int a){ return p[a] < 0? a : p[a] = findP(p[a]); }
void unite(int a, int b){
a = findP(a), b = findP(b);
if (a == b) return;
if (p[a] > p[b]) swap(a, b);
p[a] += p[b], p[b] = a;
}
inline bool f(int a, int b, ll R){ return gone[a][b] < R; }
int main(){
cin.tie(0)->sync_with_stdio(0);
ll n, q, W, H; cin >> n >> q >> W >> H;
vector<E> ee;
for (int i = 5; i <= n+4; i++){
cin >> x[i] >> y[i] >> r[i];
ee.pb({1, i, H-y[i]-r[i]});
ee.pb({2, i, W-x[i]-r[i]});
ee.pb({3, i, y[i]-r[i]});
ee.pb({4, i, x[i]-r[i]});
for (int j = 5; j < i; j++){
ee.pb({j, i, (ll)(sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j])});
}
}
sort(all(ee), [](const E &i, const E &j){ return i.w < j.w; });
ms(gone, -1); ms(p, -1);
for (auto[a, b, w]: ee){
unite(a, b);
for (int i = 1; i <= 4; i++){
for (int j = i+1; j <= 4; j++){
if (gone[i][j] == -1 && findP(i) == findP(j)) gone[i][j] = gone[j][i] = w;
}
}
}
while (q--){
ll R, pp; cin >> R >> pp; R *= 2;
vector<bool> ok(5, 1);
if (pp == 1){
if (f(3, 4, R)) ok[2] = ok[3] = ok[4] = 0; //Lower left
if (f(4, 1, R)) ok[4] = 0; //Upper left
if (f(1, 2, R)) ok[3] = 0; //Upper right
if (f(2, 3, R)) ok[2] = 0; //Lower right
if (f(1, 3, R)) ok[2] = ok[3] = false; // Vert
if (f(2, 4, R)) ok[4] = ok[3] = false; //Horz
} else if (pp == 2){
if (f(3, 4, R)) ok[1] = 0; //Lower left
if (f(4, 1, R)) ok[4] = 0; //Upper left
if (f(1, 2, R)) ok[3] = 0; //Upper right
if (f(2, 3, R)) ok[1] = ok[3] = ok[4] = 0; //Lower right
if (f(1, 3, R)) ok[1] = ok[4] = false; // Vert
if (f(2, 4, R)) ok[4] = ok[3] = false; //Horz
} else if (pp == 3){
if (f(3, 4, R)) ok[1] = 0; //Lower left
if (f(4, 1, R)) ok[4] = 0; //Upper left
if (f(1, 2, R)) ok[1] = ok[2] = ok[4] = 0; //Upper right
if (f(2, 3, R)) ok[2] = 0; //Lower right
if (f(1, 3, R)) ok[1] = ok[4] = false; // Vert
if (f(2, 4, R)) ok[1] = ok[2] = false; //Horz
} else {
if (f(3, 4, R)) ok[1] = 0; //Lower left
if (f(4, 1, R)) ok[1] = ok[2] = ok[3] = 0; //Upper left
if (f(1, 2, R)) ok[3] = 0; //Upper right
if (f(2, 3, R)) ok[2] = 0; //Lower right
if (f(1, 3, R)) ok[2] = ok[3] = false; // Vert
if (f(2, 4, R)) ok[1] = ok[2] = false; //Horz
}
for (int i = 1; i <= 4; i++) if (ok[i]) cout << i;
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
34256 KB |
Output is correct |
2 |
Correct |
174 ms |
35268 KB |
Output is correct |
3 |
Correct |
172 ms |
35272 KB |
Output is correct |
4 |
Correct |
199 ms |
34244 KB |
Output is correct |
5 |
Correct |
193 ms |
35012 KB |
Output is correct |
6 |
Correct |
175 ms |
34500 KB |
Output is correct |
7 |
Correct |
187 ms |
34504 KB |
Output is correct |
8 |
Correct |
187 ms |
35272 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
1240 KB |
Output is correct |
2 |
Correct |
27 ms |
2124 KB |
Output is correct |
3 |
Correct |
23 ms |
2260 KB |
Output is correct |
4 |
Correct |
27 ms |
2228 KB |
Output is correct |
5 |
Correct |
22 ms |
2260 KB |
Output is correct |
6 |
Correct |
24 ms |
2252 KB |
Output is correct |
7 |
Correct |
22 ms |
1876 KB |
Output is correct |
8 |
Correct |
21 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
196 ms |
34256 KB |
Output is correct |
2 |
Correct |
174 ms |
35268 KB |
Output is correct |
3 |
Correct |
172 ms |
35272 KB |
Output is correct |
4 |
Correct |
199 ms |
34244 KB |
Output is correct |
5 |
Correct |
193 ms |
35012 KB |
Output is correct |
6 |
Correct |
175 ms |
34500 KB |
Output is correct |
7 |
Correct |
187 ms |
34504 KB |
Output is correct |
8 |
Correct |
187 ms |
35272 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
24 ms |
1240 KB |
Output is correct |
12 |
Correct |
27 ms |
2124 KB |
Output is correct |
13 |
Correct |
23 ms |
2260 KB |
Output is correct |
14 |
Correct |
27 ms |
2228 KB |
Output is correct |
15 |
Correct |
22 ms |
2260 KB |
Output is correct |
16 |
Correct |
24 ms |
2252 KB |
Output is correct |
17 |
Correct |
22 ms |
1876 KB |
Output is correct |
18 |
Correct |
21 ms |
1884 KB |
Output is correct |
19 |
Correct |
211 ms |
35268 KB |
Output is correct |
20 |
Correct |
211 ms |
35524 KB |
Output is correct |
21 |
Correct |
215 ms |
35528 KB |
Output is correct |
22 |
Correct |
208 ms |
35268 KB |
Output is correct |
23 |
Correct |
208 ms |
34244 KB |
Output is correct |
24 |
Correct |
210 ms |
34504 KB |
Output is correct |