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>
using namespace std;
const int N = 2e5 + 42;
int tmp[N];
vector<int> createFunTour(int n, int q) {
int centroid = 0, dist = 0;
for(int i = 1; i < n; i++)
if(n <= 2 * attractionsBehind(0, i)) {
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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |