# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
484674 |
2021-11-05T03:12:38 Z |
phamhoanghiep |
Park (BOI16_park) |
C++14 |
|
377 ms |
57772 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
const int maxn=2005;
const int maxm=1e5+5;
vector<int> ans[maxm];
int n,m;
int w,h;
struct pt{
int x;
int y;
int r;
} trees[maxn];
int pset[maxn];
int sz[maxn];
void init() {
for(int i=1 ; i<=n ; i++) {
pset[i]=i;
sz[i]=1;
}
}
vector<pair<double,ii>> edges;
vector<pair<double,ii>> queries;
int find_set(int s) {
if(pset[s]==s) return s;
return pset[s]=find_set(pset[s]);
}
bool same_set(int u, int v) {
return find_set(u)==find_set(v);
}
void union_set(int u, int v) {
u=find_set(u); v=find_set(v);
if(u==v) return;
if(sz[u]>sz[v]) swap(u,v);
pset[u]=v;
sz[v]+=sz[u];
}
signed main() {
cin>>n>>m;
cin>>w>>h;
n+=4;
init();
for(int i=5 ; i<=n ; i++) {
cin>>trees[i].x>>trees[i].y>>trees[i].r;
edges.push_back(make_pair((double)(trees[i].x-trees[i].r),ii(1,i)));
edges.push_back(make_pair((double)(trees[i].y-trees[i].r),ii(2,i)));
edges.push_back(make_pair((double)(w-trees[i].x-trees[i].r),ii(3,i)));
edges.push_back(make_pair((double)(h-trees[i].y-trees[i].r),ii(4,i)));
}
for(int i=5 ; i<=n ; i++) {
for(int j=i+1 ; j<=n ; j++) {
edges.push_back(make_pair(sqrt((trees[i].x-trees[j].x)*(trees[i].x-trees[j].x)+(trees[i].y-trees[j].y)*(trees[i].y-trees[j].y))-trees[i].r-trees[j].r,ii(i,j)));
}
}
sort(edges.begin(),edges.end());
for(int i=1 ; i<=m ; i++) {
int r;
int st;
cin>>r>>st;
queries.push_back(make_pair(2*r,ii(st,i)));
}
sort(queries.begin(),queries.end());
int cur_id=0;
int sz=edges.size();
for(int i=0 ; i<m ; i++) {
while(cur_id<sz&&edges[cur_id].first<queries[i].first) {
union_set(edges[cur_id].second.first,edges[cur_id].second.second);
//cout<<"edges "<<cur_id<<" = "<<edges[cur_id].first<<" "<<edges[cur_id].second.first<<" "<<edges[cur_id].second.second<<endl;
cur_id++;
}
int st=queries[i].second.first;
int id=queries[i].second.second;
ans[id].push_back(st);
if(st==1) {
if((!same_set(2,1))&&(!same_set(2,3))&&(!same_set(2,4))) ans[id].push_back(2);
if((!same_set(2,1))&&(!same_set(1,3))&&(!same_set(2,4))&&(!same_set(3,4))) ans[id].push_back(3);
if((!same_set(2,1))&&(!same_set(1,3))&&(!same_set(1,4))) ans[id].push_back(4);
}
if(st==2) {
if((!same_set(2,1))&&(!same_set(2,3))&&(!same_set(2,4))) ans[id].push_back(1);
if((!same_set(3,1))&&(!same_set(2,3))&&(!same_set(3,4))) ans[id].push_back(3);
if((!same_set(2,3))&&(!same_set(1,3))&&(!same_set(1,4))&&(!same_set(2,4))) ans[id].push_back(4);
}
if(st==3) {
if((!same_set(2,1))&&(!same_set(1,3))&&(!same_set(2,4))&&(!same_set(3,4))) ans[id].push_back(1);
if((!same_set(2,3))&&(!same_set(1,3))&&(!same_set(3,4))) ans[id].push_back(2);
if((!same_set(4,1))&&(!same_set(4,3))&&(!same_set(2,4))) ans[id].push_back(4);
}
if(st==4) {
if((!same_set(2,1))&&(!same_set(1,3))&&(!same_set(1,4))) ans[id].push_back(1);
if((!same_set(4,1))&&(!same_set(1,3))&&(!same_set(2,4))&&(!same_set(3,2))) ans[id].push_back(2);
if((!same_set(2,4))&&(!same_set(4,3))&&(!same_set(1,4))) ans[id].push_back(3);
}
}
for(int i=1 ; i<=m ; i++) {
sort(ans[i].begin(),ans[i].end());
for(int u: ans[i]) cout<<u;
cout<<'\n';
}
}
/*
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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
52088 KB |
Output is correct |
2 |
Correct |
283 ms |
52020 KB |
Output is correct |
3 |
Correct |
288 ms |
52088 KB |
Output is correct |
4 |
Correct |
284 ms |
52072 KB |
Output is correct |
5 |
Correct |
283 ms |
52140 KB |
Output is correct |
6 |
Correct |
288 ms |
52088 KB |
Output is correct |
7 |
Correct |
268 ms |
52112 KB |
Output is correct |
8 |
Correct |
257 ms |
52084 KB |
Output is correct |
9 |
Correct |
1 ms |
2636 KB |
Output is correct |
10 |
Correct |
1 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
10004 KB |
Output is correct |
2 |
Correct |
97 ms |
10668 KB |
Output is correct |
3 |
Correct |
92 ms |
10464 KB |
Output is correct |
4 |
Correct |
105 ms |
10784 KB |
Output is correct |
5 |
Correct |
97 ms |
10804 KB |
Output is correct |
6 |
Correct |
103 ms |
10928 KB |
Output is correct |
7 |
Correct |
119 ms |
9908 KB |
Output is correct |
8 |
Correct |
89 ms |
9876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
286 ms |
52088 KB |
Output is correct |
2 |
Correct |
283 ms |
52020 KB |
Output is correct |
3 |
Correct |
288 ms |
52088 KB |
Output is correct |
4 |
Correct |
284 ms |
52072 KB |
Output is correct |
5 |
Correct |
283 ms |
52140 KB |
Output is correct |
6 |
Correct |
288 ms |
52088 KB |
Output is correct |
7 |
Correct |
268 ms |
52112 KB |
Output is correct |
8 |
Correct |
257 ms |
52084 KB |
Output is correct |
9 |
Correct |
1 ms |
2636 KB |
Output is correct |
10 |
Correct |
1 ms |
2636 KB |
Output is correct |
11 |
Correct |
101 ms |
10004 KB |
Output is correct |
12 |
Correct |
97 ms |
10668 KB |
Output is correct |
13 |
Correct |
92 ms |
10464 KB |
Output is correct |
14 |
Correct |
105 ms |
10784 KB |
Output is correct |
15 |
Correct |
97 ms |
10804 KB |
Output is correct |
16 |
Correct |
103 ms |
10928 KB |
Output is correct |
17 |
Correct |
119 ms |
9908 KB |
Output is correct |
18 |
Correct |
89 ms |
9876 KB |
Output is correct |
19 |
Correct |
377 ms |
57484 KB |
Output is correct |
20 |
Correct |
367 ms |
57412 KB |
Output is correct |
21 |
Correct |
370 ms |
57772 KB |
Output is correct |
22 |
Correct |
370 ms |
57068 KB |
Output is correct |
23 |
Correct |
366 ms |
57396 KB |
Output is correct |
24 |
Correct |
354 ms |
57544 KB |
Output is correct |