제출 #15684

#제출 시각아이디문제언어결과실행 시간메모리
15684gs14004철로 (IOI14_rail)C++14
30 / 100
92 ms836 KiB
#include "rail.h" #include <vector> #include <algorithm> using namespace std; typedef pair<int,int> pi; int dist0[5005], distmin[5005]; bool setCheck[5005]; vector<pi> v; void make(int location[], int stype[], int x, int st){ int last = -1; for(auto &i : v){ if(last == -1){ stype[i.second] = x; location[i.second] = location[st]; if(stype[i.second] == 1){ location[i.second] -= i.first; } else{ location[i.second] += i.first; } last = i.second; } else{ int p = getDistance(i.second, last); if(p > i.first){ stype[i.second] = x; location[i.second] = location[st]; if(stype[i.second] == 1){ location[i.second] -= i.first; } else{ location[i.second] += i.first; } last = i.second; } else{ stype[i.second] = 3 - x; location[i.second] = location[last]; if(stype[i.second] == 1){ location[i.second] -= p; } else{ location[i.second] += p; } } } } } void findLocation(int N, int first, int location[], int stype[]) { location[0] = first; stype[0] = 1; int minv = 1e9, minp = -1; for(int i=1; i<N; i++){ dist0[i] = getDistance(0,i); if(minv > dist0[i]){ minv = dist0[i]; minp = i; } } location[minp] = first + minv; stype[minp] = 2; for(int i=1; i<N; i++){ if(i == minp) continue; distmin[i] = getDistance(minp, i); if(dist0[i] == dist0[minp] + distmin[i]){ setCheck[i] = 1; } } for(int i=1; i<N; i++){ if(setCheck[i]){ v.push_back(pi(distmin[i], i)); } } sort(v.begin(), v.end()); make(location, stype, 1, minp); v.clear(); for(int i=1; i<N; i++){ if(i != minp && !setCheck[i]){ v.push_back(pi(dist0[i] - dist0[minp], i)); } } sort(v.begin(), v.end()); make(location, stype, 2, minp); v.clear(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...