# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
729002 | stevancv | Fun Tour (APIO20_fun) | C++14 | 16 ms | 2772 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"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int inf = 2e9;
vector<int> graf[N];
deque<int> dq[21];
void Dfs(int s, int t) {
dq[t].push_back(s);
for (int u : graf[s]) {
Dfs(u, t + 1);
}
}
vector<int> createFunTour(int n, int q) {
if (n <= 500) {
vector<vector<int>> g(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (hoursRequired(i, j) == 1) {
g[i].push_back(j);
g[j].push_back(i);
}
}
}
vector<int> ans;
vector<int> bia(n);
int tko = 0;
while (ans.size() < n) {
queue<int> q;
vector<int> dist(n, inf);
q.push(tko);
dist[tko] = 0;
while (!q.empty()) {
int s = q.front(); q.pop();
for (int u : g[s]) {
if (dist[u] > dist[s] + 1) {
dist[u] = dist[s] + 1;
q.push(u);
}
}
}
int mx = tko;
for (int i = 0; i < n; i++) {
if (bia[i] == 0 && dist[i] > dist[mx]) mx = i;
}
ans.push_back(mx);
bia[mx] = 1;
tko = mx;
}
return ans;
}
for (int i = 1; i < n; i++) {
int p = (i - 1) / 2;
graf[p].push_back(i);
}
Dfs(0, 0);
vector<int> ans;
int poc = 1;
for (int i = 20; i >= 0; i--) {
while (!dq[i].empty()) {
if (poc == 1) {
ans.push_back(dq[i].front());
dq[i].pop_front();
}
else {
ans.push_back(dq[i].back());
dq[i].pop_back();
}
poc ^= 1;
}
}
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... |