제출 #546304

#제출 시각아이디문제언어결과실행 시간메모리
546304amunduzbaev즐거운 행로 (APIO20_fun)C++17
66 / 100
286 ms24156 KiB
#include "fun.h" #include "bits/stdc++.h" using namespace std; #ifndef EVAL #include "grader.cpp" #endif #define ar array const int B = 894; int d[B][B]; const int MAXN = 1e5 + 5; vector<int> edges[MAXN]; vector<int> createFunTour(int n, int Q) { if(n == 2) return {0, 1}; vector<int> d(n), sub(n); for(int i=0;i<n;i++){ sub[i] = attractionsBehind(0, i); } int p = 0; for(int i=0;i<n;i++){ if(sub[i] * 2 > n && sub[i] < sub[p]){ p = i; } } vector<int> c; for(int i=0;i<n;i++){ d[i] = hoursRequired(p, i); if(d[i] == 1) c.push_back(i); } int sz = c.size(); assert(sz >= 2); vector<priority_queue<ar<int, 2>>> v(sz); for(int i=0;i<n;i++){ if(i == p) continue; int d1 = hoursRequired(i, c[0]), d2 = hoursRequired(i, c[1]); if(d1 == d2) v[2].push({d[i], i}); else { if(d1 < d2) v[0].push({d[i], i}); else v[1].push({d[i], i}); } } vector<int> P; int last = -1; while((int)P.size() < n - 1){ vector<int> t(sz); iota(t.begin(), t.end(), 0); sort(t.begin(), t.end(), [&](int i, int j){ if(v[i].empty()) return false; if(v[j].empty()) return true; return (v[i].top()[0] > v[j].top()[0]); }); int a = t[0], b = t[1]; if(sz > 2 && !v[t[2]].empty()){ if(v[t[0]].size() + v[t[1]].size() - 2 < v[t[2]].size()){ a = t[0], b = t[2]; } } if(last == a) swap(a, b); if(!v[a].empty()) P.push_back(v[a].top()[1]), v[a].pop(); if(!v[b].empty()) P.push_back(v[b].top()[1]), v[b].pop(); last = b; } P.push_back(p); //~ for(auto x : p) cout<<x<<" "; //~ cout<<endl; return P; } /* 7 400000 0 1 0 2 1 3 1 4 2 5 2 6 */
#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...