Submission #290648

#TimeUsernameProblemLanguageResultExecution timeMemory
290648KastandaFun Tour (APIO20_fun)C++11
0 / 100
10 ms9984 KiB
// M #include<bits/stdc++.h> #include "fun.h" using namespace std; const int N = 100005; int n, Centroid, H[N]; map < int , int > MP[N]; inline int GetDist(int i, int j) { if (i == j) return 0; if (MP[i][j]) return MP[i][j]; MP[i][j] = MP[j][i] = hoursRequired(i, j); return MP[i][j]; } vector < int > createFunTour(int _n, int Q) { n = _n; Centroid = 0; for (int i = 1; i < n; i ++) if (attractionsBehind(Centroid, i) * 2 > n) Centroid = i; vector < int > Ch, vec[3]; for (int i = 0; i < n; i ++) H[i] = GetDist(Centroid, i); for (int i = 0; i < n; i ++) if (H[i] == 1) Ch.push_back(i); assert((int)Ch.size() <= 3); int k = (int)Ch.size(); for (int i = 0; i < n; i ++) if (H[i] >= 1) { int j = 0; while (j + 1 < k && H[i] != GetDist(Ch[j], i) + 1) j ++; vec[j].push_back(i); } for (int i = 0; i < k; i ++) sort(vec[i].begin(), vec[i].end(), [&](int v, int u){return H[v] < H[u];}); int last = -1; vector < int > P; while (true) { int j = -1; for (int i = 0; i < k; i ++) if (i != last && (j == -1 || vec[i].size() > vec[j].size())) j = i; assert(j != -1); if (!vec[j].size()) break; P.push_back(vec[j].back()); vec[j].pop_back(); last = j; } P.push_back(Centroid); int Cnt = 0; for (int i = 0; i < k; i ++) if (vec[i].size()) Cnt ++; assert(Cnt <= 1); if (!Cnt) return P; int j = 0; while (!vec[j].size()) j ++; for (int i = 0; i < (int)vec[j].size(); i ++) { P.push_back(vec[j].back()); vec[j].pop_back(); if (i < (int)vec[j].size()) P.push_back(vec[j][i]); } return P; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...