Submission #7726

#TimeUsernameProblemLanguageResultExecution timeMemory
7726dohyun0324Rail (IOI14_rail)C++98
30 / 100
89 ms748 KiB
#include "rail.h" #include<algorithm> using namespace std; int w,arr1[5010],arr2[5010]; struct data { int num,dis; bool operator<(const data&r)const { if(dis==r.dis) return num>r.num; return dis<r.dis; } }left[5010]; struct data2 { int num,dis; bool operator<(const data2&r)const { if(dis==r.dis) return num<r.num; return dis<r.dis; } }right[5010]; void findLocation(int N, int first, int location[], int stype[]) { int i,k,dis=2147483647,p,s,dis2; for(i=1;i<=N-1;i++) { k=getDistance(0,i); arr1[i]=k; if(dis>k) dis=k, p=i; } stype[0]=1, location[0]=first; stype[p]=2, location[p]=dis+location[0]; for(i=1;i<=N-1;i++) { if(i==p) continue; arr2[i]=getDistance(p,i); } dis2=dis; for(i=1;i<=N-1;i++) { if(i==p) continue; if(arr1[i]-arr2[i]==dis && arr2[i]-dis<0) { location[i]=location[p]-arr2[i]; stype[i]=1; if(dis2>arr2[i]) dis2=arr2[i]; } } for(i=1;i<=N-1;i++) { if(i==p) continue; if(arr1[i]-arr2[i]==dis && arr2[i]-dis>0) { w++; left[w].dis=arr2[i]-dis; left[w].num=i; } } sort(left+1,left+w+1); if(w>0){stype[left[1].num]=1; location[left[1].num]=first-left[1].dis;} s=1; for(i=2;i<=w;i++) { k=getDistance(left[i].num,left[s].num); if(k==left[i].dis-left[s].dis) { stype[left[i].num]=2; location[left[i].num]=location[left[s].num]+k; } else { stype[left[i].num]=1; location[left[i].num]=first-left[i].dis; s=i; } } w=0; for(i=1;i<=N-1;i++) { if(i==p) continue; if(arr1[i]-arr2[i]==dis-2*dis2) { w++; right[w].dis=arr1[i]-dis; right[w].num=i; } } sort(right+1,right+w+1); if(w>0){stype[right[1].num]=2; location[right[1].num]=first+dis+right[1].dis;} s=1; for(i=2;i<=w;i++) { k=getDistance(right[i].num,right[s].num); if(k==right[i].dis-right[s].dis) { stype[right[i].num]=1; location[right[i].num]=location[right[s].num]-k; } else { stype[right[i].num]=2; location[right[i].num]=first+dis+right[i].dis; s=i; } } }

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:33:12: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
     stype[p]=2, location[p]=dis+location[0];
            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...