#include "swaps.h"
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cassert>
#define EB emplace_back
#define X first
#define Y second
#define MP make_pair
using namespace std;
typedef pair<int, int> pii;
void solve(int n, int v) {
int m = 1;
vector<int> ANS;
for(; m < n; m <<= 1) {}
for(int i = 0; i < m; ++i) ANS.EB(i + 1);
for(int i = 1 << 1; i <= m; i <<= 1)
for(int j = i >> 1; j; j >>= 1) {
vector<pii> S;
for(int k = 0; k < m; ++k) {
int _k = k, l = k ^ j;
if(l > _k) {
if(_k & i) swap(l, _k);
S.EB(MP(_k, l));
// printf("sche %d[%d] %d[%d]\n", ANS[_k], _k, ANS[l], l);
if(ANS[_k] <= n && ANS[l] <= n) schedule(ANS[_k], ANS[l]);
}
}
vector<int> RES = visit();
for(int k = 0, cnt = 0; k < S.size(); ++k) {
int a = S[k].X, b = S[k].Y;
if(ANS[a] <= n && ANS[b] <= n) {
assert(cnt < RES.size());
if(!RES[cnt]) swap(ANS[a], ANS[b]);
++cnt;
} else if(ANS[a] > n && ANS[b] <= n) { swap(ANS[a], ANS[b]); }
}
S.clear();
}
// for(int i = 0; i < m; ++i) printf("%d%c", ANS[i], " \n"[i == m - 1]);
for(int i = 0; i < m - n; ++i) ANS.pop_back();
answer(ANS);
}
/*
for(int i = 0, j = 0; i < RES.size(); ++i) {
if(!RES[i])
swap(ANS[S[i].X], ANS[S[i].Y]);
}
*/
Compilation message
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:36:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int k = 0, cnt = 0; k < S.size(); ++k) {
| ~~^~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
from swaps.cpp:5:
swaps.cpp:39:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | assert(cnt < RES.size());
| ~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
428 KB |
Correct |
3 |
Correct |
1 ms |
344 KB |
Correct |
4 |
Correct |
3 ms |
436 KB |
Correct |
5 |
Correct |
3 ms |
616 KB |
Correct |
6 |
Correct |
3 ms |
432 KB |
Correct |
7 |
Correct |
3 ms |
936 KB |
Correct |
8 |
Correct |
3 ms |
428 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
428 KB |
Correct |
3 |
Correct |
2 ms |
344 KB |
Correct |
4 |
Correct |
4 ms |
680 KB |
Correct |
5 |
Correct |
3 ms |
684 KB |
Correct |
6 |
Correct |
3 ms |
684 KB |
Correct |
7 |
Correct |
3 ms |
428 KB |
Correct |
8 |
Correct |
3 ms |
684 KB |
Correct |
9 |
Correct |
3 ms |
680 KB |
Correct |
10 |
Correct |
3 ms |
848 KB |
Correct |
11 |
Correct |
4 ms |
684 KB |
Correct |
12 |
Correct |
3 ms |
684 KB |
Correct |
13 |
Correct |
4 ms |
684 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Correct |
2 |
Correct |
1 ms |
428 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Correct |
2 |
Correct |
1 ms |
428 KB |
Correct |
3 |
Correct |
1 ms |
344 KB |
Correct |
4 |
Correct |
1 ms |
608 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
608 KB |
Correct |
3 |
Correct |
2 ms |
344 KB |
Correct |
4 |
Correct |
3 ms |
684 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
608 KB |
Correct |
3 |
Correct |
2 ms |
344 KB |
Correct |
4 |
Correct |
3 ms |
684 KB |
Correct |
5 |
Correct |
0 ms |
344 KB |
Correct |
6 |
Correct |
1 ms |
424 KB |
Correct |
7 |
Correct |
2 ms |
344 KB |
Correct |
8 |
Correct |
3 ms |
680 KB |
Correct |
9 |
Correct |
3 ms |
436 KB |
Correct |
10 |
Correct |
3 ms |
928 KB |
Correct |
11 |
Correct |
3 ms |
684 KB |
Correct |
12 |
Correct |
4 ms |
680 KB |
Correct |
13 |
Correct |
0 ms |
344 KB |
Correct |
14 |
Correct |
1 ms |
424 KB |
Correct |
15 |
Correct |
2 ms |
344 KB |
Correct |
16 |
Correct |
3 ms |
1188 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
420 KB |
Correct |
3 |
Correct |
1 ms |
344 KB |
Correct |
4 |
Correct |
3 ms |
432 KB |
Correct |
5 |
Correct |
3 ms |
432 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
420 KB |
Correct |
3 |
Correct |
1 ms |
344 KB |
Correct |
4 |
Correct |
3 ms |
432 KB |
Correct |
5 |
Correct |
3 ms |
432 KB |
Correct |
6 |
Correct |
0 ms |
344 KB |
Correct |
7 |
Correct |
1 ms |
424 KB |
Correct |
8 |
Correct |
1 ms |
344 KB |
Correct |
9 |
Correct |
3 ms |
1184 KB |
Correct |
10 |
Correct |
4 ms |
1184 KB |
Correct |
11 |
Correct |
4 ms |
688 KB |
Correct |
12 |
Correct |
3 ms |
436 KB |
Correct |
13 |
Correct |
3 ms |
688 KB |
Correct |
14 |
Correct |
3 ms |
680 KB |
Correct |
15 |
Correct |
3 ms |
680 KB |
Correct |
16 |
Correct |
3 ms |
680 KB |
Correct |
17 |
Correct |
4 ms |
592 KB |
Correct |
18 |
Correct |
3 ms |
688 KB |
Correct |
19 |
Correct |
0 ms |
344 KB |
Correct |
20 |
Correct |
1 ms |
600 KB |
Correct |
21 |
Correct |
1 ms |
344 KB |
Correct |
22 |
Correct |
3 ms |
428 KB |
Correct |
23 |
Correct |
3 ms |
680 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
428 KB |
Correct |
3 |
Correct |
2 ms |
344 KB |
Correct |
4 |
Correct |
3 ms |
680 KB |
Correct |
5 |
Correct |
4 ms |
1188 KB |
Correct |
6 |
Correct |
3 ms |
624 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
428 KB |
Correct |
3 |
Correct |
2 ms |
344 KB |
Correct |
4 |
Correct |
3 ms |
680 KB |
Correct |
5 |
Correct |
4 ms |
1188 KB |
Correct |
6 |
Correct |
3 ms |
624 KB |
Correct |
7 |
Correct |
0 ms |
344 KB |
Correct |
8 |
Correct |
1 ms |
420 KB |
Correct |
9 |
Correct |
1 ms |
344 KB |
Correct |
10 |
Correct |
3 ms |
936 KB |
Correct |
11 |
Correct |
3 ms |
680 KB |
Correct |
12 |
Correct |
3 ms |
428 KB |
Correct |
13 |
Correct |
3 ms |
432 KB |
Correct |
14 |
Correct |
3 ms |
680 KB |
Correct |
15 |
Correct |
3 ms |
1440 KB |
Correct |
16 |
Correct |
3 ms |
680 KB |
Correct |
17 |
Correct |
3 ms |
428 KB |
Correct |
18 |
Correct |
3 ms |
436 KB |
Correct |
19 |
Correct |
3 ms |
932 KB |
Correct |
20 |
Correct |
0 ms |
344 KB |
Correct |
21 |
Correct |
1 ms |
608 KB |
Correct |
22 |
Correct |
1 ms |
344 KB |
Correct |
23 |
Correct |
3 ms |
684 KB |
Correct |
24 |
Correct |
3 ms |
684 KB |
Correct |
25 |
Correct |
4 ms |
844 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
608 KB |
Correct |
3 |
Correct |
1 ms |
344 KB |
Correct |
4 |
Correct |
3 ms |
688 KB |
Correct |
5 |
Correct |
3 ms |
672 KB |
Correct |
6 |
Correct |
4 ms |
660 KB |
Correct |
7 |
Correct |
3 ms |
556 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
608 KB |
Correct |
3 |
Correct |
1 ms |
344 KB |
Correct |
4 |
Correct |
3 ms |
688 KB |
Correct |
5 |
Correct |
3 ms |
672 KB |
Correct |
6 |
Correct |
4 ms |
660 KB |
Correct |
7 |
Correct |
3 ms |
556 KB |
Correct |
8 |
Correct |
0 ms |
344 KB |
Correct |
9 |
Correct |
0 ms |
344 KB |
Correct |
10 |
Correct |
1 ms |
420 KB |
Correct |
11 |
Correct |
1 ms |
344 KB |
Correct |
12 |
Correct |
3 ms |
684 KB |
Correct |
13 |
Correct |
3 ms |
436 KB |
Correct |
14 |
Correct |
3 ms |
436 KB |
Correct |
15 |
Correct |
4 ms |
936 KB |
Correct |
16 |
Correct |
4 ms |
684 KB |
Correct |
17 |
Correct |
3 ms |
932 KB |
Correct |
18 |
Correct |
4 ms |
1192 KB |
Correct |
19 |
Correct |
4 ms |
1688 KB |
Correct |
20 |
Correct |
3 ms |
1188 KB |
Correct |
21 |
Correct |
3 ms |
680 KB |
Correct |
22 |
Correct |
0 ms |
596 KB |
Correct |
23 |
Correct |
1 ms |
428 KB |
Correct |
24 |
Correct |
1 ms |
344 KB |
Correct |
25 |
Correct |
3 ms |
432 KB |
Correct |
26 |
Correct |
3 ms |
680 KB |
Correct |
27 |
Correct |
3 ms |
636 KB |
Correct |
28 |
Correct |
3 ms |
1100 KB |
Correct |