#include <bits/stdc++.h>
#include "swaps.h"
using namespace std;
const int MAXN = 50;
vector<array<int, 2>> ops[MAXN];
int sz, n;
int bitonic(int l, int r, bool inc, int lvl, bool isbitonic)
{
if(l == r)
return lvl - 1;
int md = (l + r) >> 1, mx = lvl - 1;
if(!isbitonic)
{
mx = bitonic(l, md, inc, lvl, 0);
bitonic(md + 1, r, !inc, lvl, 0);
}
for(int i = l; i <= md; i++)
{
int x = i, y = i + md + 1 - l;
if(!inc)
ops[mx + 1].push_back({x, y});
else
ops[mx + 1].push_back({y, x});
}
bitonic(l, md, inc, mx + 2, 1);
return bitonic(md + 1, r, inc, mx + 2, 1);
}
void solve(int N, int v)
{
n = N;
if(n == 1)
{
answer({1});
return;
}
sz = 1 << (__lg(n - 1) + 1);
vector<int> a(sz);
for(int i = 0; i < sz; i++)
a[i] = i + 1;
int dep = bitonic(0, sz - 1, 1, 0, 0);
assert(dep < MAXN);
for(int j = 0; j < MAXN; j ++)
{
if(ops[j].empty()) continue;
for(auto [x, y] : ops[j])
if(a[x] <= n && a[y] <= n)
schedule(a[x], a[y]);
vector<int> ret = visit();
int cnt = 0;
for(auto [x, y] : ops[j])
{
if(a[x] > n)
continue;
if(a[y] > n)
{
swap(a[x], a[y]);
continue;
}
if (ret[cnt])
swap(a[x], a[y]);
cnt ++;
}
}
while(a.size() > n)
a.pop_back();
answer(a);
}
Compilation message
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:50:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
50 | for(auto [x, y] : ops[j])
| ^
swaps.cpp:55:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
55 | for(auto [x, y] : ops[j])
| ^
swaps.cpp:69:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
69 | while(a.size() > n)
| ~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
2 ms |
336 KB |
Correct |
4 |
Correct |
3 ms |
556 KB |
Correct |
5 |
Correct |
3 ms |
552 KB |
Correct |
6 |
Correct |
3 ms |
552 KB |
Correct |
7 |
Correct |
3 ms |
556 KB |
Correct |
8 |
Correct |
4 ms |
696 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
2 ms |
336 KB |
Correct |
4 |
Correct |
4 ms |
736 KB |
Correct |
5 |
Correct |
3 ms |
552 KB |
Correct |
6 |
Correct |
4 ms |
568 KB |
Correct |
7 |
Correct |
3 ms |
560 KB |
Correct |
8 |
Correct |
3 ms |
552 KB |
Correct |
9 |
Correct |
4 ms |
708 KB |
Correct |
10 |
Correct |
3 ms |
728 KB |
Correct |
11 |
Correct |
3 ms |
552 KB |
Correct |
12 |
Correct |
3 ms |
556 KB |
Correct |
13 |
Correct |
5 ms |
552 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
1 ms |
336 KB |
Correct |
4 |
Correct |
2 ms |
336 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
2 ms |
336 KB |
Correct |
4 |
Correct |
3 ms |
556 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
2 ms |
336 KB |
Correct |
4 |
Correct |
3 ms |
556 KB |
Correct |
5 |
Correct |
1 ms |
336 KB |
Correct |
6 |
Correct |
1 ms |
336 KB |
Correct |
7 |
Correct |
2 ms |
336 KB |
Correct |
8 |
Correct |
4 ms |
556 KB |
Correct |
9 |
Correct |
3 ms |
556 KB |
Correct |
10 |
Correct |
3 ms |
552 KB |
Correct |
11 |
Correct |
5 ms |
556 KB |
Correct |
12 |
Correct |
4 ms |
556 KB |
Correct |
13 |
Correct |
1 ms |
336 KB |
Correct |
14 |
Correct |
1 ms |
336 KB |
Correct |
15 |
Correct |
2 ms |
504 KB |
Correct |
16 |
Correct |
5 ms |
556 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
2 ms |
336 KB |
Correct |
3 |
Correct |
2 ms |
336 KB |
Correct |
4 |
Correct |
4 ms |
560 KB |
Correct |
5 |
Correct |
3 ms |
556 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
2 ms |
336 KB |
Correct |
3 |
Correct |
2 ms |
336 KB |
Correct |
4 |
Correct |
4 ms |
560 KB |
Correct |
5 |
Correct |
3 ms |
556 KB |
Correct |
6 |
Correct |
2 ms |
504 KB |
Correct |
7 |
Correct |
1 ms |
336 KB |
Correct |
8 |
Correct |
2 ms |
504 KB |
Correct |
9 |
Correct |
5 ms |
556 KB |
Correct |
10 |
Correct |
4 ms |
556 KB |
Correct |
11 |
Correct |
4 ms |
556 KB |
Correct |
12 |
Correct |
4 ms |
560 KB |
Correct |
13 |
Correct |
4 ms |
552 KB |
Correct |
14 |
Correct |
3 ms |
556 KB |
Correct |
15 |
Correct |
4 ms |
568 KB |
Correct |
16 |
Correct |
4 ms |
788 KB |
Correct |
17 |
Correct |
3 ms |
572 KB |
Correct |
18 |
Correct |
5 ms |
556 KB |
Correct |
19 |
Correct |
1 ms |
336 KB |
Correct |
20 |
Correct |
1 ms |
336 KB |
Correct |
21 |
Correct |
2 ms |
336 KB |
Correct |
22 |
Correct |
3 ms |
556 KB |
Correct |
23 |
Correct |
4 ms |
556 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
2 ms |
336 KB |
Correct |
4 |
Correct |
5 ms |
560 KB |
Correct |
5 |
Correct |
3 ms |
552 KB |
Correct |
6 |
Correct |
4 ms |
544 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
2 ms |
336 KB |
Correct |
4 |
Correct |
5 ms |
560 KB |
Correct |
5 |
Correct |
3 ms |
552 KB |
Correct |
6 |
Correct |
4 ms |
544 KB |
Correct |
7 |
Correct |
1 ms |
336 KB |
Correct |
8 |
Correct |
2 ms |
336 KB |
Correct |
9 |
Correct |
2 ms |
496 KB |
Correct |
10 |
Correct |
3 ms |
556 KB |
Correct |
11 |
Correct |
4 ms |
560 KB |
Correct |
12 |
Correct |
3 ms |
552 KB |
Correct |
13 |
Correct |
5 ms |
556 KB |
Correct |
14 |
Correct |
5 ms |
804 KB |
Correct |
15 |
Correct |
4 ms |
552 KB |
Correct |
16 |
Correct |
3 ms |
560 KB |
Correct |
17 |
Correct |
4 ms |
552 KB |
Correct |
18 |
Correct |
6 ms |
552 KB |
Correct |
19 |
Correct |
4 ms |
560 KB |
Correct |
20 |
Correct |
1 ms |
336 KB |
Correct |
21 |
Correct |
1 ms |
336 KB |
Correct |
22 |
Correct |
2 ms |
336 KB |
Correct |
23 |
Correct |
4 ms |
552 KB |
Correct |
24 |
Correct |
5 ms |
556 KB |
Correct |
25 |
Correct |
5 ms |
544 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
2 ms |
336 KB |
Correct |
4 |
Correct |
3 ms |
512 KB |
Correct |
5 |
Correct |
3 ms |
564 KB |
Correct |
6 |
Correct |
3 ms |
548 KB |
Correct |
7 |
Correct |
3 ms |
544 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct |
2 |
Correct |
1 ms |
336 KB |
Correct |
3 |
Correct |
2 ms |
336 KB |
Correct |
4 |
Correct |
3 ms |
512 KB |
Correct |
5 |
Correct |
3 ms |
564 KB |
Correct |
6 |
Correct |
3 ms |
548 KB |
Correct |
7 |
Correct |
3 ms |
544 KB |
Correct |
8 |
Correct |
1 ms |
336 KB |
Correct |
9 |
Correct |
1 ms |
336 KB |
Correct |
10 |
Correct |
2 ms |
336 KB |
Correct |
11 |
Correct |
3 ms |
504 KB |
Correct |
12 |
Correct |
3 ms |
560 KB |
Correct |
13 |
Correct |
5 ms |
336 KB |
Correct |
14 |
Correct |
5 ms |
336 KB |
Correct |
15 |
Correct |
5 ms |
804 KB |
Correct |
16 |
Correct |
3 ms |
552 KB |
Correct |
17 |
Correct |
3 ms |
560 KB |
Correct |
18 |
Correct |
5 ms |
556 KB |
Correct |
19 |
Correct |
3 ms |
560 KB |
Correct |
20 |
Correct |
3 ms |
556 KB |
Correct |
21 |
Correct |
3 ms |
556 KB |
Correct |
22 |
Correct |
1 ms |
336 KB |
Correct |
23 |
Correct |
1 ms |
336 KB |
Correct |
24 |
Correct |
2 ms |
336 KB |
Correct |
25 |
Correct |
4 ms |
560 KB |
Correct |
26 |
Correct |
4 ms |
556 KB |
Correct |
27 |
Correct |
4 ms |
548 KB |
Correct |
28 |
Correct |
4 ms |
548 KB |
Correct |