Submission #1062882

#TimeUsernameProblemLanguageResultExecution timeMemory
1062882NemanjaSo2005Rail (IOI14_rail)C++17
56 / 100
360 ms98648 KiB
#include "rail.h" #include<bits/stdc++.h> #define ll long long using namespace std; const int maxn=5005; int kesh[maxn][maxn],N,idxC,idxD,poz[maxn],tip[maxn],najb[maxn]; int dist(int a,int b){ if(a==b) return 0; if(kesh[a][b]==-2){ // cout<<a<<" - "<<b<<": "; int x=getDistance(a,b); // cout<<x<<endl; kesh[a][b]=kesh[b][a]=x; } return kesh[a][b]; } void findLocation(int n, int first, int location[], int stype[]){ N=n; for(int i=0;i<N;i++) for(int j=0;j<N;j++) kesh[i][j]=-2; location[0]=first; stype[0]=1; if(N==1) return; for(int i=0;i<N;i++){ if(i==0) najb[i]=1; else najb[i]=0; for(int j=0;j<N;j++){ if(j==i) continue; if(dist(i,j)<dist(i,najb[i])) najb[i]=j; } } idxD=najb[0]; tip[idxD]=2; poz[idxD]=first+dist(0,idxD); idxC=najb[idxD]; tip[idxC]=1; poz[idxC]=poz[idxD]-dist(idxD,idxC); /* for(int i=0;i<N;i++) cout<<i<<": "<<najb[i]<<endl; cout<<idxC<<" "<<idxD<<endl;*/ for(int i=1;i<N;i++){ if(i==idxC or i==idxD) continue; if(najb[i]==idxC){ tip[i]=2; poz[i]=poz[idxC]+dist(i,idxC); continue; } if(najb[i]==idxD){ tip[i]=1; poz[i]=poz[idxD]-dist(i,idxD); continue; } int dc=dist(i,idxC); int dd=dist(i,idxD); int xx=najb[i]; int yy=najb[xx]; int zzz=0; if(min(dist(xx,idxC),dist(xx,idxD))<min(dist(yy,idxC),dist(yy,idxD))) zzz=1; else zzz=0; int dn=min(dist(najb[i],idxC),dist(najb[i],idxD)); if(dd<dc){ if(zzz==1){ tip[i]=2; poz[i]=poz[idxD]-dn+dist(najb[i],i); } else{ tip[i]=1; poz[i]=poz[idxD]-dd; } } else{ if(zzz==1){ tip[i]=1; poz[i]=poz[idxC]+dn-dist(najb[i],i); } else{ tip[i]=2; poz[i]=poz[idxC]+dc; } } } for(int i=1;i<N;i++){ location[i]=poz[i]; stype[i]=tip[i]; } } /* 3 15 1 8 1 1 1 2 1 3 2 4 2 5 1 6 2 7 2 9 2 10 1 11 1 12 2 13 1 14 2 15 1 4 1 1 2 4 2 7 2 9 2 6 1 3 2 6 2 7 1 1 1 0 2 8 3 8 1 1 1 25 2 26 1 12 2 18 1 3 2 19 2 10 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...