//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define mem(a,v) memset((a),(v),sizeof(a))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 2e3 + 5;
const double eps = 1e-9;
int adj[MAXN][MAXN], ans[4][4], x[MAXN], y[MAXN], r[MAXN], par[MAXN];
int mx[MAXN][MAXN];
vi adj2[MAXN];
vector<pair<int,pii>> edg;
int qry(int x) { return x == par[x] ? x : par[x] = qry(par[x]); }
void join(int u, int v) { u = qry(u), v = qry(v); par[u] = v; }
void dfs(int u, int p, int root, int val) {
mx[root][u] = val;
for (int v: adj2[u])
if (v != p)
dfs(v, u, root, max(val, adj[u][v]));
}
int main() {
memset(adj,0x3f,sizeof adj);
int n, m, w, h;
scanf("%d %d %d %d", &n, &m, &w, &h);
for (int j = n; j <= n + 4; j++) {
par[j] = j;
for (int i = n; i < j; i++)
edg.pb({0x3fffffff, {i, j}});
}
for (int i = 0; i < n; i++) {
par[i] = i;
scanf("%d %d %d", &x[i], &y[i], &r[i]);
for (int j = 0; j < i; j++) {
adj[i][j] = adj[j][i] = (int) floor((hypot(x[i]-x[j],y[i]-y[j])-r[i]-r[j])/2.+eps);
edg.pb({adj[i][j], {i, j}});
}
adj[i][n+0]=adj[n+0][i]=(y[i]-r[i])/2;
adj[i][n+1]=adj[n+1][i]=(x[i]-r[i])/2;
adj[i][n+2]=adj[n+2][i]=(w-x[i]-r[i])/2;
adj[i][n+3]=adj[n+3][i]=(h-y[i]-r[i])/2;
for (int j = 0; j < 4; j++)
edg.pb({adj[i][n+j], {i, n+j}});
}
sort(edg.begin(), edg.end());
for (int i = 0; i < edg.size(); i++) {
int w = edg[i].fi, u, v;
tie(u, v) = edg[i].se;
if (qry(u) != qry(v))
adj2[u].pb(v), adj2[v].pb(u);
join(u, v);
}
for (int i = n; i < n + 4; i++) {
dfs(i, -1, i, 0);
ans[i-n][i-n]=0x3fffffff;
}
ans[0][1]=ans[1][0]=min(mx[n][n+1],min(mx[n][n+2],mx[n][n+3]));
ans[0][2]=ans[2][0]=min(min(mx[n][n+1],mx[n][n+3]),min(mx[n+2][n+1],mx[n+2][n+3]));
ans[0][3]=ans[3][0]=min(mx[n+1][n],min(mx[n+1][n+2],mx[n+1][n+3]));
ans[1][2]=ans[2][1]=min(mx[n+2][n],min(mx[n+2][n+1],mx[n+2][n+3]));
ans[1][3]=ans[3][1]=min(min(mx[n][n+2],mx[n][n+3]),min(mx[n+1][n+2],mx[n+1][n+3]));
ans[2][3]=ans[3][2]=min(mx[n+3][n],min(mx[n+3][n+1],mx[n+3][n+2]));
for (int i = 0; i < m; i++) {
int r, e;
scanf("%d %d", &r, &e);
for (int j = 0; j < 4; j++)
if (r <= ans[e-1][j])
printf("%d", j+1);
printf("\n");
}
}
Compilation message
park.cpp: In function 'int main()':
park.cpp:75:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < edg.size(); i++) {
~~^~~~~~~~~~~~
park.cpp:76:10: warning: unused variable 'w' [-Wunused-variable]
int w = edg[i].fi, u, v;
^
park.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d %d", &n, &m, &w, &h);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:62:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &x[i], &y[i], &r[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
park.cpp:94:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &r, &e);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
392 ms |
40904 KB |
Output is correct |
2 |
Correct |
406 ms |
41316 KB |
Output is correct |
3 |
Correct |
388 ms |
41048 KB |
Output is correct |
4 |
Correct |
426 ms |
40944 KB |
Output is correct |
5 |
Correct |
398 ms |
41036 KB |
Output is correct |
6 |
Correct |
417 ms |
41008 KB |
Output is correct |
7 |
Correct |
350 ms |
40904 KB |
Output is correct |
8 |
Correct |
355 ms |
40904 KB |
Output is correct |
9 |
Correct |
16 ms |
16128 KB |
Output is correct |
10 |
Correct |
15 ms |
16128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
17948 KB |
Output is correct |
2 |
Correct |
72 ms |
18036 KB |
Output is correct |
3 |
Correct |
63 ms |
17908 KB |
Output is correct |
4 |
Correct |
65 ms |
18064 KB |
Output is correct |
5 |
Correct |
68 ms |
17876 KB |
Output is correct |
6 |
Correct |
75 ms |
18164 KB |
Output is correct |
7 |
Correct |
59 ms |
17700 KB |
Output is correct |
8 |
Correct |
57 ms |
17656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
392 ms |
40904 KB |
Output is correct |
2 |
Correct |
406 ms |
41316 KB |
Output is correct |
3 |
Correct |
388 ms |
41048 KB |
Output is correct |
4 |
Correct |
426 ms |
40944 KB |
Output is correct |
5 |
Correct |
398 ms |
41036 KB |
Output is correct |
6 |
Correct |
417 ms |
41008 KB |
Output is correct |
7 |
Correct |
350 ms |
40904 KB |
Output is correct |
8 |
Correct |
355 ms |
40904 KB |
Output is correct |
9 |
Correct |
16 ms |
16128 KB |
Output is correct |
10 |
Correct |
15 ms |
16128 KB |
Output is correct |
11 |
Correct |
69 ms |
17948 KB |
Output is correct |
12 |
Correct |
72 ms |
18036 KB |
Output is correct |
13 |
Correct |
63 ms |
17908 KB |
Output is correct |
14 |
Correct |
65 ms |
18064 KB |
Output is correct |
15 |
Correct |
68 ms |
17876 KB |
Output is correct |
16 |
Correct |
75 ms |
18164 KB |
Output is correct |
17 |
Correct |
59 ms |
17700 KB |
Output is correct |
18 |
Correct |
57 ms |
17656 KB |
Output is correct |
19 |
Correct |
439 ms |
41392 KB |
Output is correct |
20 |
Correct |
433 ms |
41240 KB |
Output is correct |
21 |
Correct |
440 ms |
41296 KB |
Output is correct |
22 |
Correct |
444 ms |
41260 KB |
Output is correct |
23 |
Correct |
476 ms |
41264 KB |
Output is correct |
24 |
Correct |
419 ms |
41584 KB |
Output is correct |