Submission #1281237

#TimeUsernameProblemLanguageResultExecution timeMemory
1281237repmannRail (IOI14_rail)C++20
30 / 100
55 ms57312 KiB
#include <bits/stdc++.h> #include "rail.h" using namespace std; int N; int DIST[5000][5000]; //int getDistance(int i, int j) //{ // cout << i << ' ' << j << '\n'; // int ret; // cin >> ret; // return ret; //} void findLocation(int n, int location0, int location[], int stype[]) { N = n; stype[0] = 1; location[0] = location0; vector <pair <int, int>> V, L, R; for(int i = 1; i < N; i++) { DIST[0][i] = DIST[i][0] = getDistance(0, i); V.push_back({DIST[0][i], i}); } sort(V.begin(), V.end()); int d = V.begin()->second; stype[d] = 2; location[d] = location[0] + V.begin()->first; for(int i = 1; i < N; i++) { if(i == d) continue; DIST[d][i] = DIST[i][d] = getDistance(d, i); } for(int i = 1; i < N; i++) { if(i == d) continue; if(DIST[0][i] == (DIST[0][d] + DIST[d][i])) L.push_back({DIST[d][i], i}); else R.push_back({DIST[0][i], i}); } if(L.size()) { sort(L.begin(), L.end()); while(L.begin()->first < DIST[d][0]) { stype[L.begin()->second] = 1; location[L.begin()->second] = location[d] - L.begin()->first; L.erase(L.begin(), L.begin() + 1); } } if(L.size()) { int prevc = L.begin()->second; stype[prevc] = 1; location[prevc] = location[d] - DIST[d][prevc]; for(int i = 1; i < L.size(); i++) { DIST[prevc][L[i].second] = DIST[L[i].second][prevc] = getDistance(prevc, L[i].second); if(DIST[d][L[i].second] == (DIST[d][prevc] + DIST[prevc][L[i].second])) { stype[L[i].second] = 2; location[L[i].second] = location[prevc] + DIST[prevc][L[i].second]; } else { prevc = L[i].second; stype[prevc] = 1; location[prevc] = location[d] - DIST[d][prevc]; } } } if(R.size()) { sort(R.begin(), R.end()); int prevd = R.begin()->second; stype[prevd] = 2; location[prevd] = location[0] + DIST[0][prevd]; for(int i = 1; i < R.size(); i++) { DIST[prevd][R[i].second] = DIST[R[i].second][prevd] = getDistance(prevd, R[i].second); if(DIST[0][R[i].second] == (DIST[0][prevd] + DIST[prevd][R[i].second])) { stype[R[i].second] = 1; location[R[i].second] = location[prevd] - DIST[prevd][R[i].second]; } else { prevd = R[i].second; stype[prevd] = 2; location[prevd] = location[0] + DIST[0][prevd]; } } } return; } //int main() //{ // int n, location0; // cin >> n >> location0; // int location[n], stype[n]; // findLocation(n, location0, location, stype); // for(int i = 0; i < n; i++) cout << location[i] << " \n"[i == (n - 1)]; // for(int i = 0; i < n; i++) cout << stype[i] << " \n"[i == (n - 1)]; // return 0; //}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...