제출 #1026132

#제출 시각아이디문제언어결과실행 시간메모리
1026132socpite철로 (IOI14_rail)C++17
100 / 100
48 ms780 KiB
#include "rail.h" #include<bits/stdc++.h> using namespace std; const int maxn = 5e3 + 5; int distC[maxn], distD[maxn]; void findLocation(int N, int first, int location[], int stype[]) { vector<pair<int, int>> vec; int fd = -1; for(int i = 1; i < N; i++){ distC[i] = getDistance(0, i); if(fd == -1 || distC[i] < distC[fd])fd = i; } stype[fd] = 2; location[fd] = first + distC[fd]; distD[0] = distC[fd]; int fc = 0; for(int i = 1; i < N; i++){ if(i == fd)continue; distD[i] = getDistance(fd, i); if(distD[i] < distD[fc])fc = i; } stype[fc] = 1; location[fc] = location[fd] - distD[fc]; for(int i = 1; i < N; i++){ distC[i] -= location[fc] - first; } distC[0] = distD[0] + distD[fc]; // cout << fc << " " << fd << endl; // for(int i = 0; i < N; i++){ // cout << distC[i] << " " << distD[i] << endl; // } // cout << "SUS" << endl; for(int i = 0; i < N; i++){ if(i == fc || i == fd)continue; if(distC[i] > distD[i])vec.push_back({distD[i], i}); } sort(vec.begin(), vec.end()); set<int> st; st.insert(location[fc]); int mxid = fc; for(auto v: vec){ int d = getDistance(v.second, mxid); int fakepos = *st.begin() + d; int checkdist = fakepos + location[fd] - *prev(st.upper_bound(fakepos))*2; if(checkdist == v.first && st.find(fakepos) == st.end()){ location[v.second] = fakepos; stype[v.second] = 2; } else { mxid = v.second; location[v.second] = location[fd] - v.first; st.insert(location[v.second]); stype[v.second] = 1; } } st.clear(); vec.clear(); for(int i = 0; i < N; i++){ if(i == fc || i == fd)continue; if(distC[i] < distD[i])vec.push_back({distC[i], i}); } sort(vec.begin(), vec.end()); st.insert(location[fd]); mxid = fd; for(auto v: vec){ int d = getDistance(v.second, mxid); int fakepos = *st.rbegin() - d; int checkdist = *st.lower_bound(fakepos)*2 - location[fc] - fakepos; if(checkdist == v.first && st.find(fakepos) == st.end()){ location[v.second] = fakepos; stype[v.second] = 1; } else { mxid = v.second; location[v.second] = location[fc] + v.first; st.insert(location[v.second]); stype[v.second] = 2; } } // for(int i = 0; i < N; i++)cout << stype[i] << " " << location[i] << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...