Submission #130919

#TimeUsernameProblemLanguageResultExecution timeMemory
130919Mahdi_JfriRail (IOI14_rail)C++14
56 / 100
615 ms99084 KiB
#include "rail.h" #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back const int maxn = 5e3 + 20; int d[maxn][maxn]; void findLocation(int N, int first, int location[], int stype[]) { int n = N; for(int i = 0; i < n; i++) for(int j = i + 1; j < n; j++) d[i][j] = d[j][i] = getDistance(i , j); vector<pair<int , int> > tmp; for(int i = 1; i < n; i++) tmp.pb({d[0][i] , i}); sort(tmp.begin() , tmp.end()); vector<int> rd; for(auto x : tmp) { int v = x.second; bool bad = 0; if(!rd.empty()) { int lx = d[0][rd.back()] - d[rd.back()][v]; int tmp = -1; for(auto u : rd) if(d[0][u] >= lx) { tmp = u; break; } if(d[0][v] == d[v][tmp] + d[tmp][0]) bad = 1; } if(!bad) rd.pb(v) , stype[v] = 2; } tmp.clear(); while(rd.empty()); int r = rd.back(); for(int i = 0; i < n; i++) if(i != r) tmp.pb({d[r][i] , i}); sort(tmp.begin() , tmp.end()); rd.clear(); for(auto x : tmp) { int v = x.second; bool bad = 0; if(!rd.empty()) { int lx = d[r][rd.back()] - d[rd.back()][v]; int tmp = -1; for(auto u : rd) if(d[r][u] >= lx) { tmp = u; break; } if(d[r][v] == d[v][tmp] + d[tmp][r]) bad = 1; } if(!bad) rd.pb(v) , stype[v] = 1; } for(int i = 0; i < n; i++) if(!stype[i]) stype[i] = 2; location[r] = first + d[0][r]; for(int i = 0; i < n; i++) if(stype[i] == 1) location[i] = location[r] - d[r][i]; for(int i = 0; i < n; i++) if(stype[i] == 2) location[i] = location[rd.back()] + d[rd.back()][i]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...