제출 #889320

#제출 시각아이디문제언어결과실행 시간메모리
889320JakobZorzRail (IOI14_rail)C++17
30 / 100
57 ms604 KiB
#include"rail.h" #include<iostream> #include<vector> #include<algorithm> typedef long long ll; using namespace std; void findLocation(int n,int first,int location[],int stype[]){ vector<pair<int,int>>dist0; vector<int>dist_from_0(n); for(int i=1;i<n;i++){ dist_from_0[i]=getDistance(0,i); dist0.emplace_back(dist_from_0[i],i); } sort(dist0.begin(),dist0.end()); vector<int>left,right; stype[0]=1; location[0]=0; //for(auto i:dist0) //cout<<i.first<<" "<<i.second<<"\n"; for(auto[dist,i]:dist0){ if(right.empty()){ right.push_back(i); location[i]=dist; stype[i]=2; continue; } int dist1=getDistance(right[0],i); //cout<<dist1<<" + "<<dist_from_0[right[0]]<<" == "<<dist<<"\n"; if(dist1+dist_from_0[right[0]]==dist){ // i is on the left side dist-=2*dist_from_0[right[0]]; bool done=false; for(int j=0;j<(int)left.size()-1;j++){ int a=location[left[j]]; int b=location[left[j+1]]; int nloc=2*a+dist; if(a<nloc&&nloc<b){ int dist2=getDistance(left[j],i); if(dist2-a==dist){ done=true; location[i]=nloc; stype[i]=2; } } } if(!done){ left.push_back(i); location[i]=-dist; stype[i]=1; } }else{ // i is on the right side bool done=false; for(int j=1;j<(int)right.size()-1;j++){ int a=location[right[j]]; int b=location[right[j+1]]; int nloc=2*b-dist; if(a<nloc&&nloc<b){ int dist2=getDistance(right[j+1],i); if(dist2+b==dist){ done=true; location[i]=nloc; stype[i]=1; } } } if(!done){ right.push_back(i); location[i]=dist; stype[i]=2; } } } for(int i=0;i<n;i++){ location[i]+=first; //cout<<stype[i]<<" "<<location[i]<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...