제출 #126743

#제출 시각아이디문제언어결과실행 시간메모리
126743anayk철로 (IOI14_rail)C++14
30 / 100
85 ms604 KiB
#include <algorithm> #include "rail.h" #define U 1 #define D 0 #define L 0 #define R 1 void findLocation(int N, int first, int location[], int stype[]) { stype[0] = 1; location[0] = first; std::pair<int, int> d[N-1]; for(int i = 1; i < N; i++) { d[i-1].first = getDistance(0, i); d[i-1].second = i; } std::sort(d, d+N-1); int hinge = d[0].second; int ends[2][2]; for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) ends[i][j] = -1; ends[U][L] = ends[U][R] = d[0].second; ends[D][R] = 0; location[hinge] = d[0].first + first; stype[hinge] = 2; for(int i = 1; i < N-1; i++) { int u = d[i].second; int a = getDistance(u, hinge); if(a + d[0].first == d[i].first) { if(ends[D][L] == -1) { ends[D][L] = u; location[u] = location[hinge] - a; stype[u] = 1; continue; } int b = getDistance(u, ends[D][L]); int x = location[ends[D][L]] + 2*(location[ends[U][L]] - location[ends[D][L]]) - b; int y = location[hinge] - a; if(x == y) { location[u] = x; stype[u] = 1; ends[D][L] = u; } else { location[u] = location[ends[D][L]] + b; stype[u] = 2; if(location[u] < location[ends[U][L]]) ends[U][L] = u; } } else { int b = getDistance(u, ends[U][R]); int x = b + location[ends[U][R]] - 2*(location[ends[U][R]] - location[ends[D][R]]); int y = d[i].first + first; if(x == y) { location[u] = x; stype[u] = 2; ends[U][R] = u; } else { location[u] = location[ends[U][R]] - b; stype[u] = 1; if(location[u] > location[ends[D][R]]) ends[D][R] = u; } } } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...