제출 #793003

#제출 시각아이디문제언어결과실행 시간메모리
793003I_Love_EliskaM_철로 (IOI14_rail)C++14
30 / 100
260 ms109244 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]; void findLocation(int n, int p, int ans[], int type[]) { 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...