제출 #496950

#제출 시각아이디문제언어결과실행 시간메모리
496950Temmie철로 (IOI14_rail)C++17
100 / 100
84 ms16120 KiB
#include "rail.h" #include <bits/stdc++.h> //int getDistance(int i, int j) { //return 0; //} void findLocation(int n, int first, int location[], int stype[]) { location[0] = first, stype[0] = 1; std::vector <int> inv(int(4e6) + 3, -1); inv[first] = 0; if (n == 1) { return; } std::vector <std::pair <int, int>> a(n - 1); for (int i = 1; i < n; i++) { a[i - 1] = { getDistance(0, i), i }; } std::sort(a.rbegin(), a.rend()); int l = 0, r = a.back().second; location[r] = first + a.back().first; stype[r] = 2; inv[location[r]] = r; a.pop_back(); while (a.size()) { int ind = a.back().second; a.pop_back(); int left = getDistance(l, ind); int right = getDistance(r, ind); int loc1 = location[l] + left; int loc2 = location[r] - right; int mid = (loc1 + loc2) >> 1; if (inv[mid] != -1) { stype[ind] = stype[inv[mid]] == 1 ? 2 : 1; } else if (first < mid) { stype[ind] = 2; } else { stype[ind] = 1; } if (stype[ind] == 1) { std::swap(loc1, loc2); } location[ind] = loc1; inv[location[ind]] = ind; if (loc1 > location[r]) { r = ind; } else if (loc1 < location[l]) { l = ind; } } } //int main() { //}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...