Submission #28221

#TimeUsernameProblemLanguageResultExecution timeMemory
28221noobprogrammerRail (IOI14_rail)C++14
100 / 100
137 ms896 KiB
#include "rail.h" #include <bits/stdc++.h> using namespace std ; #define ii pair<int,int> #define fi first #define se second #define vi vector<int> #define vii vector<ii> int from0[5010] , from1[5010] ; vii le , ri , D , C ; bool cmp(ii a, ii b){ return a.se < b.se ; } void findLocation(int n, int zr , int loc[], int tp[]){ int mn = 1e9 , opt = -1 ; for(int i=1;i<n;i++) { from0[i] = getDistance(0, i) ; if(from0[i] < mn){ mn = from0[i] ; opt = i ; } } from1[0] = from0[opt] ; loc[0] = zr ; tp[0] = 1 ; loc[opt] = zr + from0[opt] ; tp[opt] = 2 ; for(int i=1 ; i<n ;i++){ if(i == opt) continue ; from1[i] = getDistance( opt , i ) ; if(from1[i] + from0[opt] == from0[i]){ if(from1[i] > from0[opt]) le.push_back({i , from1[i]}) ; else loc[i] = loc[opt] - from1[i] , tp[i] = 1 ; } else{ ri.push_back({i , from0[i]}) ; } } sort(le.begin() , le.end() , cmp ) ; sort(ri.begin() , ri.end() , cmp ) ; for(ii v : ri){ if(D.empty()) { D.push_back(v) ; loc[v.fi] = loc[0] + v.se ; tp[v.fi] = 2 ; } else{ ii cur = D.back() ; int dst = getDistance(cur.fi , v.fi) ; bool chk = 0 ; for(ii nd : D){ if(nd.se + dst - cur.se + nd.se == v.se){ tp[v.fi] = 1 ; loc[v.fi] = loc[nd.fi] - (dst - cur.se + nd.se) ; chk = 1 ; break ; } } if(!chk) { D.push_back(v) ; loc[v.fi] = loc[0] + v.se ; tp[v.fi] = 2 ; } } } D.clear() ; for(ii v : le){ if(D.empty()) { D.push_back(v) ; loc[v.fi] = loc[opt] - v.se ; tp[v.fi] = 1 ; } else{ ii cur = D.back() ; int dst = getDistance(cur.fi , v.fi) ; bool chk = 0 ; for(ii nd : D){ if(nd.se + dst - cur.se + nd.se == v.se){ tp[v.fi] = 2 ; loc[v.fi] = loc[nd.fi] + (dst - cur.se + nd.se) ; chk = 1 ; break ; } } if(!chk) { D.push_back(v) ; loc[v.fi] = loc[opt] - v.se ; tp[v.fi] = 1 ; } } } // for(int i=0;i<n;i++) printf("%d %d\n" , loc[i] , tp[i]) ; return ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...