Submission #793118

#TimeUsernameProblemLanguageResultExecution timeMemory
793118I_Love_EliskaM_Rail (IOI14_rail)C++14
30 / 100
268 ms109200 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) 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]; for (int i=0; i<n; ++i) { if (i==0 || i==f || i==s) continue; int u=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]; if (x<y) { int a=d[f][u]; int b=d[f][v]; if (a<b) { type[u]=2; ans[u]=ans[f]+a; } else { type[u]=1; ans[u]=ans[f]+a-2*mn[u]; } } else { int a=d[s][u]; int b=d[s][v]; if (a<b) { type[u]=1; ans[u]=ans[s]-a; } else { type[u]=2; ans[u]=ans[s]-a+2*mn[u]; } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...