This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
// --- Sample implementation for the task swaps ---
//
// To compile this program with the sample grader, place:
// swaps.h swaps_sample.cpp sample_grader.cpp
// in a single folder and run:
// g++ swaps_sample.cpp sample_grader.cpp
// in this folder.
//
#include "swaps.h"
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
using namespace std;
using ll = long long;
template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }
mt19937 mt(random_device{}());
void solve(int N, int V) {
vector<vector<int>> g(N);
rep (_, V) {
vector<int> P(N); iota(all(P), 0);
shuffle(all(P), mt);
rep (i, N / 2) schedule(P[i * 2] + 1, P[i * 2 + 1] + 1);
auto res = visit();
rep (i, N / 2) {
if (res[i]) g[P[i * 2]].push_back(P[i * 2 + 1]);
else g[P[i * 2 + 1]].push_back(P[i * 2]);
}
}
vector<int> tps;
{
vector<bool> used(N);
vector<int> ord;
auto dfs = [&](auto&& self, int v) -> void {
used[v] = true;
for (int u : g[v]) if (!used[u]) self(self, u);
ord.push_back(v);
};
rep (v, N) if (!used[v]) dfs(dfs, v);
reverse(all(ord));
tps = ord;
}
rep (i, N) ++tps[i];
answer(tps);
}
# | 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... |
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |