Submission #1101912

#TimeUsernameProblemLanguageResultExecution timeMemory
1101912_8_8_Rail (IOI14_rail)C++17
30 / 100
100 ms99404 KiB
#include "rail.h" #include <bits/stdc++.h> using namespace std; const int N = 5e3 + 12; int mem[N][N]; int get(int i, int j) { if(i > j) swap(i, j); if(mem[i][j] != -1) return mem[i][j]; return mem[i][j] = getDistance(i, j); } map<int, vector<int>> id; void findLocation(int32_t n, int32_t first, int32_t pos[], int32_t s[]) { memset(mem, -1, sizeof(mem)); for(int i = 0; i < n; i++) { s[i] = 0; } s[0] = 1; pos[0] = first; int L = 0; vector<pair<int, int>> a; for(int i = 1; i < n; i++) { a.push_back({get(0, i), i}); } sort(a.rbegin(), a.rend()); int R = a.back().second; int u = R; s[R] = 2; pos[R] = pos[0] + a.back().first; a.pop_back(); reverse(a.begin(), a.end()); for(auto [f, j]:a) { id[f].push_back(j); } for(auto [f, vec]:id) { // for(int j:vec) { // int val = get(L, R); // if(!s[j]) { // int mb = pos[L] + get(L, j); // if(mb < pos[R]) { // int cur = L; // for(int i = 0; i < n; i++) { // if(s[i] == 1 && pos[i] > pos[cur] && pos[i] < mb) { // cur = i; // } // } // if(get(R, j) == pos[R] - pos[cur] + mb - pos[cur]) { // s[j] = 2; // pos[j] = mb; // } // } // } // if(!s[j]) { // int mb = pos[R] - get(R, j); // if(mb > pos[L]) { // int cur = R; // for(int i = 0; i < n; i++) { // if(s[i] == 2 && pos[i] < pos[cur] && pos[i] > mb) { // cur = i; // } // } // if(get(L, j) == pos[cur] * 2 - pos[L] - mb) { // s[j] = 1; // pos[j] = mb; // } // } // } // if(s[j] == 1 && pos[j] < pos[L]) { // L = j; // } // if(s[j] == 2 && pos[j] > pos[R]) { // R = j; // } // } for(int j:vec) { if(s[j]) continue; if(!s[j]) { int mb = pos[L] + get(L, j); if(mb > pos[R]) { int cur =L; for(int i = 0; i < n; i++) { if(s[i] == 1 && pos[i] > pos[cur]) { cur = i; } } if(get(R, j) == pos[R] - pos[cur] + mb - pos[cur]) { s[j] = 2; pos[j] = mb; } } } if(!s[j]) { int mb = pos[R] - get(R, j); int cur = R; for(int i = 0; i < n; i++) { if(s[i] == 2 && pos[i] < pos[cur]) { cur = i; } } if(get(L, j) == pos[cur] - pos[L] + pos[cur] - mb) { s[j] = 1; pos[j] = mb; } } if(s[j] == 1 && pos[j] < pos[L]) { L = j; } if(s[j] == 2 && pos[j] > pos[R]) { R = j; } } // return; } } //1119 3300 2 762810 764347

Compilation message (stderr)

rail.cpp: In function 'void findLocation(int32_t, int32_t, int32_t*, int32_t*)':
rail.cpp:28:9: warning: unused variable 'u' [-Wunused-variable]
   28 |     int u = R;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...