제출 #94444

#제출 시각아이디문제언어결과실행 시간메모리
94444fjzzq2002철로 (IOI14_rail)C++14
100 / 100
99 ms1784 KiB
#include "rail.h" #include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; #define fi first #define se second #define pb push_back map<pii,int> ms; int qry(int a,int b) { if(a==b) return 0; if(a>b) swap(a,b); if(ms.count(pii(a,b))) return ms[pii(a,b)]; return ms[pii(a,b)]=getDistance(a,b); } int d1[5005],d2[5005]; void findLocation(int n, int x, int l[], int s[]) { l[0]=x; s[0]=1; if(n==1) return; for(int i=0;i<n;++i) d1[i]=qry(0,i); int r; { pii mi(2e9,2e9); for(int i=1;i<n;++i) mi=min(mi,pii(d1[i],i)); r=mi.se; } l[r]=x+d1[r]; s[r]=2; for(int i=0;i<n;++i) d2[i]=qry(r,i); vector<pii> L,R; for(int t=1;t<n;++t) if(t!=r) { pii u(d1[t],t); if(d1[t]==d1[r]+d2[t]) { if(d2[t]<=d1[r]) l[t]=l[r]-d2[t], s[t]=1; else L.pb(u); } else R.pb(u); } sort(L.begin(),L.end()); sort(R.begin(),R.end()); { set<int> xs; xs.insert(l[r]); int g=r; for(auto _:R) { int t=_.se; int dt=(d1[g]+qry(g,t)-d1[t])/2; if(xs.count(l[g]-dt)) l[t]=l[g]-qry(g,t), s[t]=1; else l[t]=l[0]+d1[t], s[t]=2, g=t, xs.insert(l[t]); // cerr<<t<<"w"<<l[t]<<" "<<s[t]<<"\n"; } } { set<int> xs; xs.insert(l[0]); int g=0; for(auto _:L) { int t=_.se; int dt=(d2[g]+qry(g,t)-d2[t])/2; if(xs.count(l[g]+dt)) l[t]=l[g]+qry(g,t), s[t]=2; else l[t]=l[r]-d2[t], s[t]=1, g=t, xs.insert(l[t]); } } // for(auto u:L) // cerr<<u.se<<",";cerr<<"L\n"; // for(auto u:R) // cerr<<u.se<<",";cerr<<"R\n"; // cerr<<0<<"w"<<r<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...