Submission #19030

#TimeUsernameProblemLanguageResultExecution timeMemory
19030suhgyuho_williamRail (IOI14_rail)C++98
56 / 100
226 ms940 KiB
#include "rail.h" #include <algorithm> #include <stdio.h> using namespace std; int dis0[5010]; int disx[5010]; int bef[5010],next[5010]; int op[5010],num[5010]; bool cmp(int x,int y){ return dis0[x] < dis0[y]; } bool cmp2(int x,int y){ return disx[x] < disx[y]; } void findLocation(int N, int first, int location[], int stype[]){ int i,j,k; int small,x; int t,v,nv; int rear; location[0] = first; stype[0] = 1; small = 999999999; for(i=1; i<N; i++){ dis0[i] = getDistance(0,i); if(small > dis0[i]){ small = dis0[i]; x = i; } } location[x] = first+dis0[x]; stype[x] = 2; for(i=1; i<N; i++){ if(i == x) continue; disx[i] = getDistance(x,i); if(dis0[i] == dis0[x]+disx[i]) op[i] = 2; else op[i] = 1; } rear = 0; for(i=1; i<N; i++){ if(op[i] == 1){ rear++; num[rear] = i; } } sort(num+1,num+rear+1,cmp); for(i=1; i<=rear; i++){ v = num[i]; for(j=i-1; j>=1; j--){ nv = num[j]; if(stype[nv] == 1) continue; t = getDistance(nv,v); if(dis0[nv]+t == dis0[v]){ stype[v] = 1; location[v] = location[nv]-t; break; } } if(j == 0){ stype[v] = 2; location[v] = first+dis0[v]; k = v; } } rear = 0; for(i=1; i<N; i++){ if(op[i] == 2){ rear++; num[rear] = i; } } sort(num+1,num+rear+1,cmp2); for(i=1; i<=rear; i++){ v = num[i]; for(j=i-1; j>=1; j--){ nv = num[j]; if(stype[nv] == 2) continue; t = getDistance(nv,v); if(disx[v] == disx[nv]+t){ location[v] = location[nv]+t; stype[v] = 2; break; } } if(j == 0){ stype[v] = 1; location[v] = location[x]-disx[v]; k = v; } } //for(i=0; i<N; i++) printf("%d %d\n",stype[i],location[i]); }

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:19:10: warning: variable 'k' set but not used [-Wunused-but-set-variable]
  int i,j,k;
          ^
rail.cpp:33:31: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
     location[x] = first+dis0[x];
                         ~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...