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 <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>
#include <numeric>
#include "swaps.h"
using namespace std;
void solve(int N, int V) {
vector<int> ans(N); iota(ans.begin(), ans.end(), 1);
for (int p = 1; p < N; p *= 2)
for (int k = p; k; k /= 2) {
for (int j = k % p; j <= N - k - 1; j += k * 2)
for (int i = 0; i <= min(k - 1, N - j - k - 1); ++i)
if ((i + j) / (p * 2) == (i + j + k) / (p * 2))
schedule(ans[i + j], ans[i + j + k]);
vector<int> res = visit(); int cnt = 0;
for (int j = k % p; j <= N - k - 1; j += k * 2)
for (int i = 0; i <= min(k - 1, N - j - k - 1); ++i)
if ((i + j) / (p * 2) == (i + j + k) / (p * 2))
if (!res[cnt++]) swap(ans[i + j], ans[i + j + k]);
}
answer(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... |
# | 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... |