# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
699478 | cig32 | Fun Tour (APIO20_fun) | C++17 | 1 ms | 304 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 "bits/stdc++.h"
#include "fun.h"
using namespace std;
#include <vector>
std::vector<int> createFunTour(int N, int Q) {
if(N == 2) return {0, 1};
int rt;
int ma=-1;
for(int i=0; i<N; i++) {
int ab = attractionsBehind(0, i);
if(N - ab <= N/2) {
if(N - ab > ma) {
ma=N - ab, rt=i;
}
}
}
int dist[N];
for(int i=0; i<N; i++) dist[i] = hoursRequired(rt, i);
vector<int> leader;
int M = 0;
for(int i=0; i<N; i++) {
if(dist[i] == 1) {
M++;
leader.push_back(i);
}
}
priority_queue<pair<int, int> > depths[M];
for(int i=0; i<N; i++) {
int grp = M-1;
for(int j=0; j<M-1; j++) {
int hr = hoursRequired(leader[j], i);
if(hr + 1 == dist[i]) {
grp = j; break;
}
}
depths[grp].push({dist[i], i});
}
vector<int> ans;
ma = -1;
int id;
for(int i=0; i<M; i++) {
if((int) (depths[i].size()) > ma) {
ma = depths[i].size();
id = i;
}
}
ans.push_back(depths[id].top().second);
depths[id].pop();
for(int i=0; i<N-1; i++) {
ma = -1;
int id2;
for(int j=0; j<M; j++) {
if((int) (depths[j].size()) > ma) {
ma = depths[j].size();
id2 = j;
}
}
if(id == id2) {
ma = -1;
for(int j=0; j<M; j++) {
if(j != id && depths[j].size() && depths[j].top().first > ma) {
ma = depths[j].top().first;
id2 = j;
}
}
}
ans.push_back(depths[id2].top().second);
depths[id2].pop();
id = id2;
}
return ans;
}
Compilation message (stderr)
# | 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... |