제출 #399311

#제출 시각아이디문제언어결과실행 시간메모리
399311phathnv철로 (IOI14_rail)C++11
100 / 100
92 ms836 KiB
#include <bits/stdc++.h> #include "rail.h" using namespace std; const int N = 5000; int dist[N], ord[N]; vector<int> adj[N]; void findLocation(int n, int first, int location[], int stype[]){ for(int i = 1; i < n; i++) dist[i] = getDistance(0, i); for(int i = 0; i < n; i++) ord[i] = i; sort(ord, ord + n, [&](const int &a, const int &b){ return dist[a] < dist[b]; }); map<int, int> m; int a = 0, b = ord[1]; location[a] = first; location[b] = first + dist[b]; stype[a] = 1; stype[b] = 2; m[location[a]] = stype[a]; m[location[b]] = stype[b]; for(int i = 2; i < n; i++){ int u = ord[i]; int dA = getDistance(a, u); int dB = getDistance(b, u); int mid = (location[a] + dA + location[b] - dB) / 2; if (m[mid] == 1 || (m[mid] == 0 && location[0] < mid)){ location[u] = location[a] + dA; stype[u] = 2; if (location[u] > location[b]) b = u; } else { location[u] = location[b] - dB; stype[u] = 1; if (location[u] < location[a]) a = u; } m[location[u]] = stype[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...