제출 #793138

#제출 시각아이디문제언어결과실행 시간메모리
793138I_Love_EliskaM_철로 (IOI14_rail)C++14
56 / 100
276 ms109340 KiB
#include "rail.h" #include <bits/stdc++.h> using namespace std; #define forn(i,n) for(int i=0;i<n;++i) #define pb push_back const int inf=1e9; const int N=5555; int d[N][N]; int mn[N]; int to[N]; int Q=0; int lim; int ask(int i, int j) { ++Q; assert(Q<=lim); return getDistance(i,j); } void findLocation(int n, int p, int ans[], int type[]) { if (n==1) { ans[0]=p, type[0]=1; return; } lim=n*(n-1)/2; forn(i,n) mn[i]=inf; forn(i,n) { forn(j,i) { int x = getDistance(i,j); d[i][j]=d[j][i]=x; mn[i]=min(mn[i],x); mn[j]=min(mn[j],x); } } forn(i,n) if (mn[i]==0) exit(1); forn(i,n) forn(j,n) if (d[i][j]==mn[i]) to[i]=j; ans[0]=p; type[0]=1; ans[to[0]]=p+mn[0]; type[to[0]]=2; ans[to[to[0]]]=ans[to[0]]-mn[to[0]]; type[to[to[0]]]=1; int f=to[to[0]], s=to[0]; //forn(i,n) { // forn(j,n) cout<<d[i][j]<<' '; cout<<'\n'; //} for (int i=0; i<n; ++i) { if ((i==0) || (i==f) || (i==s)) continue; int u=to[to[i]], v=to[i]; if (v==f) { type[i]=2; ans[i]=ans[f]+mn[i]; continue; } if (v==s) { type[i]=1; ans[i]=ans[s]-mn[i]; continue; } int x=d[f][u], y=d[s][u]; //cout<<"! "<<i<<": "<<u<<' '<<v<<' '<<x<<' '<<y<<' '<<f<<' '<<s<<'\n'; if (x<y) { int a=d[f][u]; int b=d[f][v]; if (a<b) { type[i]=2; ans[i]=ans[f]+d[f][i]; } else { type[i]=1; ans[i]=ans[f]+d[f][i]-2*mn[i]; } } else { int a=d[s][u]; int b=d[s][v]; if (a<b) { type[i]=1; ans[i]=ans[s]-d[s][i]; } else { type[i]=2; ans[i]=ans[s]-d[s][i]+2*mn[i]; } } } //forn(i,n) cout<<type[i]<<' '<<ans[i]<<'\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...