Submission #50304

#TimeUsernameProblemLanguageResultExecution timeMemory
50304top34051Rail (IOI14_rail)C++17
30 / 100
632 ms67904 KiB
#include "rail.h" #include<bits/stdc++.h> using namespace std; const int maxn = 5e3 + 10; int d0[maxn], a[maxn], rough[maxn]; int pos; int ban[maxn]; int rec[maxn][maxn]; int ask(int x, int y) { if(x>y) swap(x,y); if(x==y) return 0; if(!rec[x][y]) rec[x][y] = getDistance(x,y); // printf("\task %d %d = %d\n",x,y,rec[x][y]); return rec[x][y]; } bool cmpd(int x, int y) { return d0[x]<d0[y]; } void findLocation(int N, int first, int location[], int stype[]) { //find right for(int i=0;i<N;i++) d0[i] = ask(0,i); for(int i=0;i<N;i++) a[i] = i; sort(&a[0],&a[N],cmpd); pos = a[1]; for(int i=2;i<N;i++) { int x = a[i]; if(ask(0,x)==ask(a[1],x)+ask(0,a[1])) continue; if(ask(0,x)!=ask(pos,x)+ask(0,pos)) pos = x; } // printf("pos = %d\n",pos); //solve memset(ban,0,sizeof(ban)); ban[pos] = 1; location[pos] = first + ask(0,pos); stype[pos] = 2; while(1) { int x = -1; //nearest C for(int i=0;i<N;i++) { if(!ban[i] && (x==-1 || ask(pos,i)<ask(pos,x))) { x = i; } } if(x==-1) break; ban[x] = 1; location[x] = location[pos] - ask(pos,x); stype[x] = 1; // printf("%d (%d): ",x,location[x]); //sweep right for(int i=0;i<N;i++) { if(!ban[i] && ask(pos,i)-ask(pos,x)==ask(x,i)) { ban[i] = 1; location[i] = location[x] + ask(x,i); stype[i] = 2; // printf("%d (%d) ",i,location[i]); } } // printf("\n"); } // for(int i=0;i<N;i++) printf("%d %d\n",stype[i],location[i]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...