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 "swaps.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> r;
vector<pair<int, int>> queries;
void scheduleSortingNetwork(int i, int j) {
schedule(r[i], r[j]);
queries.emplace_back(i, j);
}
void visitSortingNetwork() {
if (queries.size() == 0)
return;
vector<int> res = visit();
for (int i = 0; i < (int) res.size(); i++)
if (!res[i])
swap(r[queries[i].first], r[queries[i].second]);
queries.clear();
}
void answerSortingNetwork() {
answer(r);
}
void solve(int N, int Q) {
for (int i = 1; i <= N; i++)
r.push_back(i);
for (int k = 2; k <= 2 * N; k <<= 1) {
for (int i = 0; i < N; i++) {
int l = i ^ (k - 1);
if (i < l && l < N)
scheduleSortingNetwork(i, l);
}
visitSortingNetwork();
for (int j = k >> 2; j > 0; j >>= 1) {
for (int i = 0; i < N; i++) {
int l = i ^ j;
if (i < l && l < N)
scheduleSortingNetwork(i, l);
}
visitSortingNetwork();
}
}
answerSortingNetwork();
}
# | 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... |