Submission #548289

#TimeUsernameProblemLanguageResultExecution timeMemory
548289sidonRail (IOI14_rail)C++17
100 / 100
81 ms772 KiB
#include <bits/stdc++.h> using namespace std; #include "rail.h" void findLocation(int N, int o, int* x, int* t) { int d[N] {}, dC[N], byD[N - 1]; map<int, int> g; t[0] = g[x[0] = o] = 1; for(int v = 1; v < N; ++v) { d[v] = getDistance(0, v); byD[v-1] = v; } int c = min_element(d + 1, d + N) - d, rD = c, lD = c, rC {}, lC {}, sp {0}; t[c] = g[x[c] = o + d[c]] = 2; for(int v = 0; v < N; ++v) { dC[v] = getDistance(c, v); if(v != c && dC[v] < dC[sp]) sp = v; } sort(byD, byD + N - 1, [&](const int &i, const int &j) { if(d[i] == d[j]) return dC[i] < dC[j]; return d[i] < d[j]; }); for(const int &v : byD) if(v != c) { int z = dC[v]; if(z > (d[v] - (d[c] - dC[sp]))) { int y = getDistance(rD, v); int xU = (x[rD] + (o + d[v]) - y) / 2; if((!(((x[rD] + (o + d[v]) - y)) & 1) && g[xU] == 2)) x[v] = x[rD] - y , t[v] = 1; else x[rD = v] = o + d[v], t[v] = 2; } else { int y = getDistance(lC, v); if(!lC) x[v] = x[c] - z, t[v] = 1; else { int xU = (y + x[lC] + (x[c] - z)) / 2; if(!(((y + x[lC] + (x[c] - z))) & 1) && g[xU] == 1) x[v] = x[lC] + y, t[v] = 2; else x[v] = x[c] - z, t[v] = 1; } } if(t[v] < 2) { if(x[v] > x[rC]) rC = v; if(x[v] < x[lC]) lC = v; } else if(x[v] < x[lD]) lD = v; g[x[v]] = t[v]; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...