#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 |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
200 KB |
Correct |
3 |
Correct |
3 ms |
280 KB |
Correct |
4 |
Correct |
7 ms |
284 KB |
Correct |
5 |
Correct |
5 ms |
280 KB |
Correct |
6 |
Correct |
6 ms |
280 KB |
Correct |
7 |
Correct |
5 ms |
284 KB |
Correct |
8 |
Correct |
6 ms |
284 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
200 KB |
Correct |
3 |
Correct |
3 ms |
200 KB |
Correct |
4 |
Correct |
5 ms |
280 KB |
Correct |
5 |
Correct |
5 ms |
280 KB |
Correct |
6 |
Correct |
5 ms |
280 KB |
Correct |
7 |
Correct |
7 ms |
288 KB |
Correct |
8 |
Correct |
5 ms |
284 KB |
Correct |
9 |
Correct |
5 ms |
280 KB |
Correct |
10 |
Correct |
5 ms |
280 KB |
Correct |
11 |
Correct |
5 ms |
280 KB |
Correct |
12 |
Correct |
6 ms |
308 KB |
Correct |
13 |
Correct |
5 ms |
288 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
200 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
200 KB |
Correct |
3 |
Correct |
1 ms |
200 KB |
Correct |
4 |
Correct |
2 ms |
200 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
1 ms |
200 KB |
Correct |
3 |
Correct |
4 ms |
200 KB |
Correct |
4 |
Correct |
6 ms |
288 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
1 ms |
200 KB |
Correct |
3 |
Correct |
4 ms |
200 KB |
Correct |
4 |
Correct |
6 ms |
288 KB |
Correct |
5 |
Correct |
1 ms |
200 KB |
Correct |
6 |
Correct |
2 ms |
200 KB |
Correct |
7 |
Correct |
3 ms |
200 KB |
Correct |
8 |
Correct |
5 ms |
284 KB |
Correct |
9 |
Correct |
7 ms |
284 KB |
Correct |
10 |
Correct |
5 ms |
284 KB |
Correct |
11 |
Correct |
7 ms |
280 KB |
Correct |
12 |
Correct |
5 ms |
280 KB |
Correct |
13 |
Correct |
1 ms |
200 KB |
Correct |
14 |
Correct |
1 ms |
200 KB |
Correct |
15 |
Correct |
3 ms |
200 KB |
Correct |
16 |
Correct |
5 ms |
284 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
200 KB |
Correct |
3 |
Correct |
3 ms |
284 KB |
Correct |
4 |
Correct |
7 ms |
284 KB |
Correct |
5 |
Correct |
5 ms |
264 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
200 KB |
Correct |
3 |
Correct |
3 ms |
284 KB |
Correct |
4 |
Correct |
7 ms |
284 KB |
Correct |
5 |
Correct |
5 ms |
264 KB |
Correct |
6 |
Correct |
1 ms |
200 KB |
Correct |
7 |
Correct |
2 ms |
200 KB |
Correct |
8 |
Correct |
2 ms |
280 KB |
Correct |
9 |
Correct |
5 ms |
288 KB |
Correct |
10 |
Correct |
6 ms |
280 KB |
Correct |
11 |
Correct |
6 ms |
280 KB |
Correct |
12 |
Correct |
7 ms |
280 KB |
Correct |
13 |
Correct |
5 ms |
280 KB |
Correct |
14 |
Correct |
7 ms |
276 KB |
Correct |
15 |
Correct |
6 ms |
280 KB |
Correct |
16 |
Correct |
5 ms |
284 KB |
Correct |
17 |
Correct |
6 ms |
280 KB |
Correct |
18 |
Correct |
5 ms |
284 KB |
Correct |
19 |
Correct |
1 ms |
200 KB |
Correct |
20 |
Correct |
2 ms |
200 KB |
Correct |
21 |
Correct |
3 ms |
200 KB |
Correct |
22 |
Correct |
5 ms |
284 KB |
Correct |
23 |
Correct |
6 ms |
260 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
200 KB |
Correct |
3 |
Correct |
3 ms |
200 KB |
Correct |
4 |
Correct |
7 ms |
284 KB |
Correct |
5 |
Correct |
5 ms |
264 KB |
Correct |
6 |
Correct |
5 ms |
260 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
200 KB |
Correct |
3 |
Correct |
3 ms |
200 KB |
Correct |
4 |
Correct |
7 ms |
284 KB |
Correct |
5 |
Correct |
5 ms |
264 KB |
Correct |
6 |
Correct |
5 ms |
260 KB |
Correct |
7 |
Correct |
1 ms |
200 KB |
Correct |
8 |
Correct |
2 ms |
200 KB |
Correct |
9 |
Correct |
3 ms |
200 KB |
Correct |
10 |
Correct |
6 ms |
280 KB |
Correct |
11 |
Correct |
6 ms |
284 KB |
Correct |
12 |
Correct |
7 ms |
280 KB |
Correct |
13 |
Correct |
5 ms |
284 KB |
Correct |
14 |
Correct |
5 ms |
280 KB |
Correct |
15 |
Correct |
5 ms |
280 KB |
Correct |
16 |
Correct |
5 ms |
280 KB |
Correct |
17 |
Correct |
5 ms |
288 KB |
Correct |
18 |
Correct |
5 ms |
324 KB |
Correct |
19 |
Correct |
6 ms |
284 KB |
Correct |
20 |
Correct |
1 ms |
200 KB |
Correct |
21 |
Correct |
2 ms |
200 KB |
Correct |
22 |
Correct |
3 ms |
200 KB |
Correct |
23 |
Correct |
6 ms |
280 KB |
Correct |
24 |
Correct |
6 ms |
280 KB |
Correct |
25 |
Correct |
6 ms |
264 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
200 KB |
Correct |
3 |
Correct |
3 ms |
200 KB |
Correct |
4 |
Correct |
5 ms |
280 KB |
Correct |
5 |
Correct |
5 ms |
268 KB |
Correct |
6 |
Correct |
7 ms |
248 KB |
Correct |
7 |
Correct |
5 ms |
264 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
200 KB |
Correct |
3 |
Correct |
3 ms |
200 KB |
Correct |
4 |
Correct |
5 ms |
280 KB |
Correct |
5 |
Correct |
5 ms |
268 KB |
Correct |
6 |
Correct |
7 ms |
248 KB |
Correct |
7 |
Correct |
5 ms |
264 KB |
Correct |
8 |
Correct |
1 ms |
200 KB |
Correct |
9 |
Correct |
1 ms |
200 KB |
Correct |
10 |
Correct |
2 ms |
200 KB |
Correct |
11 |
Correct |
3 ms |
200 KB |
Correct |
12 |
Correct |
6 ms |
284 KB |
Correct |
13 |
Correct |
5 ms |
280 KB |
Correct |
14 |
Correct |
6 ms |
284 KB |
Correct |
15 |
Correct |
5 ms |
280 KB |
Correct |
16 |
Correct |
5 ms |
284 KB |
Correct |
17 |
Correct |
5 ms |
284 KB |
Correct |
18 |
Correct |
7 ms |
284 KB |
Correct |
19 |
Correct |
7 ms |
280 KB |
Correct |
20 |
Correct |
5 ms |
288 KB |
Correct |
21 |
Correct |
7 ms |
280 KB |
Correct |
22 |
Correct |
1 ms |
200 KB |
Correct |
23 |
Correct |
2 ms |
200 KB |
Correct |
24 |
Correct |
3 ms |
200 KB |
Correct |
25 |
Correct |
5 ms |
284 KB |
Correct |
26 |
Correct |
5 ms |
264 KB |
Correct |
27 |
Correct |
5 ms |
260 KB |
Correct |
28 |
Correct |
5 ms |
260 KB |
Correct |