# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
668913 | someone | Fun Tour (APIO20_fun) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "fun.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 42, INF = 1e18 + 42;
int n, q, tmp[N];
vector<int> createFunTour(int NB, int Q) {
n = NB, q = Q;
int centroid = 0, dist = 0;
for(int i = 1; i < n; i++)
if(n - attractionsBehind(0, i) <= n/2) {
int d = hoursRequired(0, i);
if(d > dist) {
dist = d;
centroid = i;
}
}
tmp[0] = dist;
tmp[centroid] = 0;
for(int i = 1; i < n; i++)
if(i != centroid)
tmp[i] = hoursRequired(i, centroid);
priority_queue<pair<int, int>> pq;
for(int i = 0; i < n; i++)
pq.push({tmp[i], i});
deque<int> pre;
vector<int> ans;
for(int i = 0; i < n; i++) {
int id = pq.top().second;
pq.pop();
if(ans.empty())
ans.push_back(id);
else {
int last = ans.back();
if(tmp[last] + tmp[id] > hoursRequired(last, id))
pre.push_back(id);
else {
ans.push_back(id);
if(!pre.empty()) {
ans.push_back(pre[0]);
pre.pop_front();
}
}
}
}
return ans;
}