Submission #127670

#TimeUsernameProblemLanguageResultExecution timeMemory
127670hamzqq9Rail (IOI14_rail)C++14
30 / 100
104 ms632 KiB
#include "rail.h" #include<bits/stdc++.h> #define st first #define nd second #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define umax(x,y) x=max(x,y) #define umin(x,y) x=min(x,y) #define ll long long #define ii pair<int,int> #define iii pair<int,ii> #define iiii pair<ii,ii> #define sz(x) ((int) x.size()) #define orta ((bas+son)/2) #define all(x) x.begin(),x.end() #define inf 1000000000 #define MOD 1000000007 #define M 1000000 #define LOG 20 #define KOK 300 #define EPS 0.0000001 using namespace std; void findLocation(int N, int first, int location[], int stype[]) { location[0]=first; stype[0]=1; vector<ii> a(N); a[0]={0,0}; for(int i=1;i<N;i++) { a[i]={getDistance(0,i),i}; } sort(a.begin(),a.end()); location[a[1].nd]=first+a[1].st; stype[a[1].nd]=2; vector<int> rails; rails.pb(0); rails.pb(a[1].nd); for(int i=2;i<N;i++) { int dsecond=getDistance(a[1].nd,a[i].nd); if(dsecond<a[i].st && location[a[1].nd]-dsecond<first) { // on the left int ds3=getDistance(rails[0],a[i].nd); int uppos=location[rails[0]]+ds3; int ne=-1; for(int j=0;j<sz(rails);j++) { if(location[rails[j]]<uppos && stype[rails[j]]==1) ne=rails[j]; } if(uppos<location[0] && ~ne && dsecond==location[a[1].nd]-location[ne]+uppos-location[ne]) { location[a[i].nd]=uppos; stype[a[i].nd]=2; } else { location[a[i].nd]=location[a[1].nd]-dsecond; stype[a[i].nd]=1; } } else { // on the right int ds3=getDistance(rails.back(),a[i].nd); int dopos=location[rails.back()]-ds3; int ne=-1; for(int j=sz(rails)-1;j>=0;j--) { if(location[rails[j]]>dopos && stype[rails[j]]==2) ne=rails[j]; } if(dopos>location[0] && ~ne && a[i].st==location[ne]-dopos+location[ne]-first) { location[a[i].nd]=dopos; stype[a[i].nd]=1; } else { location[a[i].nd]=location[0]+a[i].st; stype[a[i].nd]=2; } } if(location[a[i].nd]<location[rails[0]]) rails.insert(rails.begin(),a[i].nd); else { for(int j=sz(rails)-1;j>=0;j--) { if(location[a[i].nd]>location[rails[j]]) { rails.insert(rails.begin()+j+1,a[i].nd); break ; } } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...