#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
using pll = pair < ll, ll >;
bool B[5][4002] = {false};
bool D[5][5] = {false};
ll ataman[2002];
ll Get(ll x) {
if ( x == ataman[x]) return x;
return ataman[x] = Get(ataman[x]);
}
void Unite(int x, int y) {
x = Get(x);
y = Get(y);
if ( x == y) return ;
ataman[x] = y;
for ( int i = 1; i <= 4; i ++) B[i][y] |= B[i][x];
for (int j = 1; j <= 4; j ++) {
for (int i1 = j + 1; i1 <= 4; i1 ++) {
if ( B[j][y] && B[i1][y]) D[j][i1] = 1;
}
}
return ;
}
ll x[2002], y[2002], r[2002];
priority_queue < pll , vector <pll> , greater<pll> > Durvuntal[5];
int main() {
ll n, m, i, j, N, M, x1, Y, y1, R, ind, i1, ans;
cin >> n >> m;
cin >> N >> M;
for (i = 1; i <= n; i ++) ataman[i] = i;
for (i = 1; i <= n; i ++) {
cin >> x[i] >> y[i] >> r[i];
}
vector < pair <long long, pair < ll, ll> > > v;
for (i = 1; i <= n; i ++) {
Durvuntal[1].push({y[i] - r[i], i});
Durvuntal[2].push({N - (x[i] + r[i]), i});
Durvuntal[3].push({M - (y[i] + r[i]), i});
Durvuntal[4].push({x[i] - r[i], i});
for (j = i+ 1; j <= n; j ++) {
long long R = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
long long S = sqrt(R);
S = S - r[i] - r[j];
v.push_back({S, {i, j}});
}
}
sort(v.begin(), v.end());
vector < pair < ll, pair < ll, ll > > > Q;
for (i = 1; i <= m; i ++) {
cin >> x1 >> y1;
Q.push_back({x1, {y1, i}});
}
sort(Q.begin(), Q.end());
string Ans[m + 2];
ind= 0;
for (pair < ll, pair < ll, ll > >& P : Q) {
long long S = P.first * 2.0;
for (i = 1; i <= 4; i ++) {
while(!Durvuntal[i].empty()) {
pll Pa = Durvuntal[i].top();
if (Pa.first < S) {
Durvuntal[i].pop();
// cout << i << " " << Pa.first << endl;
R = Get(Pa.second);
B[i][R] = 1;
for (j = 1; j <= 4; j ++) {
for (i1 = j + 1; i1 <= 4; i1 ++) {
if ( B[j][R] && B[i1][R]) D[j][i1] = 1;
}
}
}
else break;
}
}
while ( ind < v.size() ) {
if ( v[ind].first >= S) break;
// cout << v[ind].first << " " << v[ind].second.first << " " << v[ind].second.second << endl;
Unite(v[ind].second.first, v[ind].second.second);
ind ++;
}
Y = P.second.first;
if ( Y == 1) {
ans = 1;
if ( !D[1][4] && !D[1][2] && !D[1][3]) ans = ans * 10 + 2;
if ( !D[1][4] && !D[2][3] && !D[1][3] && !D[2][4]) ans = ans * 10 + 3;
if ( !D[1][4] && !D[3][4] && !D[2][4]) ans = ans * 10 + 4;
}
if ( Y == 2) {
ans = 2;
if ( !D[1][4] && !D[1][2] && !D[1][3]) ans = ans * 10 + 1;
if ( !D[1][2] && !D[2][3] && !D[2][4]) ans = ans * 10 + 3;
if ( !D[1][2] && !D[3][4] && !D[2][4] && !D[1][3]) ans = ans * 10 + 4;
}
if ( Y == 3) {
ans = 3;
if ( !D[1][4] && !D[2][3] && !D[1][3] && !D[2][4]) ans = ans * 10 + 1;
if ( !D[1][2] && !D[2][3] && !D[2][4]) ans = ans * 10 + 2;
if ( !D[2][3] && !D[3][4] && !D[1][3]) ans = ans * 10 + 4;
}
if ( Y == 4) {
ans = 4;
if ( !D[1][4] && !D[3][4] && !D[2][4]) ans = ans * 10 + 1;
if ( !D[1][2] && !D[3][4] && !D[2][4] && !D[1][3]) ans = ans * 10 + 2;
if ( !D[2][3] && !D[3][4] && !D[1][3]) ans = ans * 10 + 3;
}
string str = to_string(ans);
sort(str.begin(), str.end());
Ans[P.second.second] = str;
/*
for (i = 1; i <= 4; i ++) {
for (j = i + 1; j <= 4; j ++) {
cout << D[i][j] << " ";
}
cout << endl;
}
*/
}
for (i = 1; i <= m; i ++) {
cout << Ans[i] << endl;
}
}
Compilation message
park.cpp: In function 'int main()':
park.cpp:82:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | while ( ind < v.size() ) {
| ~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
210 ms |
51156 KB |
Output is correct |
2 |
Correct |
203 ms |
49792 KB |
Output is correct |
3 |
Correct |
209 ms |
50124 KB |
Output is correct |
4 |
Correct |
205 ms |
50112 KB |
Output is correct |
5 |
Correct |
244 ms |
50116 KB |
Output is correct |
6 |
Correct |
208 ms |
50876 KB |
Output is correct |
7 |
Correct |
193 ms |
51140 KB |
Output is correct |
8 |
Correct |
185 ms |
50116 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
163 ms |
7148 KB |
Output is correct |
2 |
Correct |
164 ms |
7752 KB |
Output is correct |
3 |
Correct |
161 ms |
7860 KB |
Output is correct |
4 |
Correct |
166 ms |
8116 KB |
Output is correct |
5 |
Correct |
162 ms |
7908 KB |
Output is correct |
6 |
Correct |
161 ms |
7980 KB |
Output is correct |
7 |
Correct |
166 ms |
8128 KB |
Output is correct |
8 |
Correct |
165 ms |
7360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
210 ms |
51156 KB |
Output is correct |
2 |
Correct |
203 ms |
49792 KB |
Output is correct |
3 |
Correct |
209 ms |
50124 KB |
Output is correct |
4 |
Correct |
205 ms |
50112 KB |
Output is correct |
5 |
Correct |
244 ms |
50116 KB |
Output is correct |
6 |
Correct |
208 ms |
50876 KB |
Output is correct |
7 |
Correct |
193 ms |
51140 KB |
Output is correct |
8 |
Correct |
185 ms |
50116 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
163 ms |
7148 KB |
Output is correct |
12 |
Correct |
164 ms |
7752 KB |
Output is correct |
13 |
Correct |
161 ms |
7860 KB |
Output is correct |
14 |
Correct |
166 ms |
8116 KB |
Output is correct |
15 |
Correct |
162 ms |
7908 KB |
Output is correct |
16 |
Correct |
161 ms |
7980 KB |
Output is correct |
17 |
Correct |
166 ms |
8128 KB |
Output is correct |
18 |
Correct |
165 ms |
7360 KB |
Output is correct |
19 |
Correct |
363 ms |
57616 KB |
Output is correct |
20 |
Correct |
360 ms |
58248 KB |
Output is correct |
21 |
Correct |
366 ms |
59040 KB |
Output is correct |
22 |
Correct |
365 ms |
59032 KB |
Output is correct |
23 |
Correct |
367 ms |
59092 KB |
Output is correct |
24 |
Correct |
361 ms |
58276 KB |
Output is correct |