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 <vector>
using namespace std;
void solve(int N, int V) {
int n = N;
while (n & (n - 1)) {
n++;
}
vector<int> res(n);
for (int i=0; i<n; i++) {
res[i] = i+1;
}
for (int k = 2; k < (N + N - 1); k *= 2) {
for (int j = k/2; j > 0; j /= 2) {
for (int i = 0; i < n; i++) {
int ip = i ^ j;
if (ip > i) {
int room1, room2;
if ((i ^ k) < i) {
// expecting room at ip to be > room at i
room1 = res[ip];
room2 = res[i];
}
else {
// expecting room at i to be > room at ip
room1 = res[i];
room2 = res[ip];
}
// if expected max is out of bound, swap
// if expected min is out of bound, don't call
if (room1 > N) {
int tmp = res[i];
res[i] = res[ip];
res[ip] = tmp;
}
else {
if (room2 <= N) {
schedule(room1, room2);
}
}
}
}
vector<int> v = visit();
int idx = 0;
for (int i = 0; i < n; i++) {
int ip = i ^ j;
int room1 = res[i];
int room2 = res[ip];
if ((ip > i) && (room1 <= N) && (room2 <= N)) {
if (v[idx++] == 0) {
int tmp = res[i];
res[i] = res[ip];
res[ip] = tmp;
}
}
}
}
}
if (N < n) {
vector<int> resf(N);
for (int i = 0; i < N; i++) {
resf[i] = res[i];
}
answer(resf);
}
else {
answer(res);
}
}
# | 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... |