제출 #948069

#제출 시각아이디문제언어결과실행 시간메모리
948069koukirocksPark (BOI16_park)C++17
100 / 100
303 ms55024 KiB
#include <bits/stdc++.h> #define speed ios_base::sync_with_stdio(0); cin.tie(0) #define all(x) (x).begin(),(x).end() #define F first #define S second using namespace std; typedef long long ll; typedef double db; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll MAX=2e3+10,P=998244353; const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f; int n,m; ll w,h; struct circle{ ll x,y,r; }tree[MAX]; struct edge{ db w; ll a,b; edge(ll _a,ll _b,db _w):a(_a),b(_b),w(_w){} }; struct query{ ll r,x,id; }q[MAX*50]; int fa[MAX]; void init() { for (int i=1;i<=n+4;i++) { fa[i]=i; } } int get(int a) { return fa[a]=(fa[a]==a?a:get(fa[a])); } void unionn(int a,int b) { a=get(a); b=get(b); if (a==b) return; fa[a]=b; } int main() { speed; cin>>n>>m; cin>>w>>h; for (int i=1;i<=n;i++) { cin>>tree[i].x>>tree[i].y>>tree[i].r; } for (int i=1;i<=m;i++) { cin>>q[i].r>>q[i].x; q[i].id=i; } sort(q+1,q+m+1,[&](query a,query b) { return a.r<b.r; }); vector<edge> egs; for (int i=1;i<=n;i++) { for (int j=i+1;j<=n;j++) { ll dx=tree[i].x-tree[j].x; ll dy=tree[i].y-tree[j].y; egs.emplace_back(i,j,sqrt(dx*dx+dy*dy)-tree[i].r-tree[j].r); } } for (int i=1;i<=n;i++) { egs.emplace_back(i,n+1,tree[i].y-tree[i].r); egs.emplace_back(i,n+2,w-tree[i].x-tree[i].r); egs.emplace_back(i,n+3,h-tree[i].y-tree[i].r); egs.emplace_back(i,n+4,tree[i].x-tree[i].r); } sort(all(egs),[&](edge a,edge b){ return a.w<b.w; }); vector<int> ans(m+1); init(); int id=0; for (int i=1;i<=m;i++) { while (id<egs.size() and egs[id].w<2*q[i].r) { unionn(egs[id].a,egs[id].b); id++; // cout<<id<<" id\n"; } ans[q[i].id]=0; for (int ex=1;ex<=4;ex++) { // cout<<ex<<" :\n"; if (ex==q[i].x) { ans[q[i].id]+=(1<<ex); continue; } bool cross=false; for (int a=ex;a!=q[i].x;a=a%4+1) { for (int b=q[i].x;b!=ex;b=b%4+1) { // cout<<q[i].r<<" "<<a<<" "<<b<<" "<<(get(n+a)==get(n+b))<<"\n"; if (get(n+a)==get(n+b)) { cross=true; } } } if (!cross) ans[q[i].id]+=(1<<ex); } } for (int i=1;i<=m;i++) { for (int j=1;j<=4;j++) { if (ans[i]&(1<<j)) cout<<j; } 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 */

컴파일 시 표준 에러 (stderr) 메시지

park.cpp: In constructor 'edge::edge(ll, ll, db)':
park.cpp:26:7: warning: 'edge::b' will be initialized after [-Wreorder]
   26 |  ll a,b;
      |       ^
park.cpp:25:5: warning:   'db edge::w' [-Wreorder]
   25 |  db w;
      |     ^
park.cpp:27:2: warning:   when initialized here [-Wreorder]
   27 |  edge(ll _a,ll _b,db _w):a(_a),b(_b),w(_w){}
      |  ^~~~
park.cpp: In function 'int main()':
park.cpp:88:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   while (id<egs.size() and egs[id].w<2*q[i].r) {
      |          ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...