//
// --- Sample implementation for the task swaps ---
//
// To compile this program with the sample grader, place:
// swaps.h swaps_sample.cpp sample_grader.cpp
// in a single folder and run:
// g++ swaps_sample.cpp sample_grader.cpp
// in this folder.
//
#include "swaps.h"
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> net;
int recmer(int l, int r, int layer) {
int h = (r - l + 1) / 2;
int gap = h;
while (gap > 0) {
int st = h;
bitset<512> chk;
do {
int a =
l + st - gap < l ? l + st - gap + (r - l + 1) : l + st - gap;
int b = l + st < l ? l + st + r - l + 1 : l + st;
if (chk[a] || chk[b]) {
st++;
if (st == r - l + 1)
st = 0;
continue;
}
net[layer].push_back(minmax(a, b));
// cout << "recmer " << layer << ": " << a << " " << b << endl;
chk[a] = chk[b] = true;
st++;
if (st == r - l + 1)
st = 0;
} while (st != h);
gap /= 2;
layer++;
}
return layer;
}
int recnet(int l, int r, int layer) {
if (l + 1 == r) {
net[layer].push_back({l, r});
// cout << "elem " << layer << ": " << l << " " << r << endl;
return layer + 1;
}
int h = (r - l + 1) / 2;
layer = max(recnet(l, l + h - 1, layer), recnet(l + h, r, layer));
return recmer(l, r, layer);
}
vector<int> ptrs;
void solve(int N, int V) {
net.resize(V);
int target = 2 << (31 - __builtin_clz(N - 1));
recnet(0, target - 1, 0);
ptrs.resize(N);
iota(ptrs.begin(), ptrs.end(), 1);
for (int layer = 0; layer < net.size(); layer++) {
vector<pair<int, int>> sched;
for (auto p : net[layer]) {
if (p.first < N && p.second < N) {
schedule(ptrs[p.first], ptrs[p.second]);
sched.push_back(p);
}
}
if (sched.empty())
continue;
vector<int> v = visit();
for (int i = 0; i < v.size(); i++) {
if (v[i] == 0)
swap(ptrs[sched[i].first], ptrs[sched[i].second]);
}
}
answer(ptrs);
}
Compilation message
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:60:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int layer = 0; layer < net.size(); layer++) {
| ~~~~~~^~~~~~~~~~~~
swaps.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
344 KB |
Correct |
3 |
Correct |
1 ms |
600 KB |
Correct |
4 |
Correct |
2 ms |
600 KB |
Correct |
5 |
Correct |
3 ms |
1556 KB |
Correct |
6 |
Correct |
2 ms |
600 KB |
Correct |
7 |
Correct |
2 ms |
600 KB |
Correct |
8 |
Correct |
2 ms |
600 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
344 KB |
Correct |
3 |
Correct |
1 ms |
600 KB |
Correct |
4 |
Correct |
2 ms |
664 KB |
Correct |
5 |
Correct |
2 ms |
600 KB |
Correct |
6 |
Correct |
2 ms |
600 KB |
Correct |
7 |
Correct |
2 ms |
600 KB |
Correct |
8 |
Correct |
3 ms |
600 KB |
Correct |
9 |
Correct |
2 ms |
572 KB |
Correct |
10 |
Correct |
2 ms |
580 KB |
Correct |
11 |
Correct |
2 ms |
576 KB |
Correct |
12 |
Correct |
2 ms |
344 KB |
Correct |
13 |
Correct |
3 ms |
580 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
344 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
344 KB |
Correct |
3 |
Correct |
0 ms |
344 KB |
Correct |
4 |
Correct |
1 ms |
576 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
0 ms |
344 KB |
Correct |
3 |
Correct |
1 ms |
600 KB |
Correct |
4 |
Correct |
2 ms |
668 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
0 ms |
344 KB |
Correct |
3 |
Correct |
1 ms |
600 KB |
Correct |
4 |
Correct |
2 ms |
668 KB |
Correct |
5 |
Correct |
0 ms |
344 KB |
Correct |
6 |
Correct |
0 ms |
344 KB |
Correct |
7 |
Correct |
1 ms |
600 KB |
Correct |
8 |
Correct |
3 ms |
600 KB |
Correct |
9 |
Correct |
2 ms |
600 KB |
Correct |
10 |
Correct |
2 ms |
600 KB |
Correct |
11 |
Correct |
2 ms |
600 KB |
Correct |
12 |
Correct |
3 ms |
600 KB |
Correct |
13 |
Correct |
0 ms |
344 KB |
Correct |
14 |
Correct |
1 ms |
344 KB |
Correct |
15 |
Correct |
1 ms |
600 KB |
Correct |
16 |
Correct |
3 ms |
600 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
0 ms |
344 KB |
Correct |
3 |
Correct |
1 ms |
600 KB |
Correct |
4 |
Correct |
2 ms |
600 KB |
Correct |
5 |
Correct |
2 ms |
344 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
0 ms |
344 KB |
Correct |
3 |
Correct |
1 ms |
600 KB |
Correct |
4 |
Correct |
2 ms |
600 KB |
Correct |
5 |
Correct |
2 ms |
344 KB |
Correct |
6 |
Correct |
0 ms |
344 KB |
Correct |
7 |
Correct |
1 ms |
344 KB |
Correct |
8 |
Correct |
1 ms |
600 KB |
Correct |
9 |
Correct |
2 ms |
600 KB |
Correct |
10 |
Correct |
2 ms |
600 KB |
Correct |
11 |
Correct |
4 ms |
600 KB |
Correct |
12 |
Correct |
2 ms |
672 KB |
Correct |
13 |
Correct |
2 ms |
600 KB |
Correct |
14 |
Correct |
2 ms |
584 KB |
Correct |
15 |
Correct |
2 ms |
572 KB |
Correct |
16 |
Correct |
2 ms |
344 KB |
Correct |
17 |
Correct |
2 ms |
344 KB |
Correct |
18 |
Correct |
4 ms |
344 KB |
Correct |
19 |
Correct |
0 ms |
344 KB |
Correct |
20 |
Correct |
1 ms |
344 KB |
Correct |
21 |
Correct |
2 ms |
600 KB |
Correct |
22 |
Correct |
2 ms |
668 KB |
Correct |
23 |
Correct |
3 ms |
344 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
344 KB |
Correct |
3 |
Correct |
2 ms |
600 KB |
Correct |
4 |
Correct |
3 ms |
664 KB |
Correct |
5 |
Correct |
2 ms |
344 KB |
Correct |
6 |
Correct |
2 ms |
548 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
344 KB |
Correct |
3 |
Correct |
2 ms |
600 KB |
Correct |
4 |
Correct |
3 ms |
664 KB |
Correct |
5 |
Correct |
2 ms |
344 KB |
Correct |
6 |
Correct |
2 ms |
548 KB |
Correct |
7 |
Correct |
0 ms |
344 KB |
Correct |
8 |
Correct |
1 ms |
344 KB |
Correct |
9 |
Correct |
1 ms |
344 KB |
Correct |
10 |
Correct |
2 ms |
600 KB |
Correct |
11 |
Correct |
2 ms |
668 KB |
Correct |
12 |
Correct |
2 ms |
600 KB |
Correct |
13 |
Correct |
2 ms |
600 KB |
Correct |
14 |
Correct |
3 ms |
600 KB |
Correct |
15 |
Correct |
2 ms |
344 KB |
Correct |
16 |
Correct |
4 ms |
580 KB |
Correct |
17 |
Correct |
2 ms |
576 KB |
Correct |
18 |
Correct |
2 ms |
576 KB |
Correct |
19 |
Correct |
2 ms |
344 KB |
Correct |
20 |
Correct |
0 ms |
344 KB |
Correct |
21 |
Correct |
1 ms |
344 KB |
Correct |
22 |
Correct |
1 ms |
600 KB |
Correct |
23 |
Correct |
3 ms |
668 KB |
Correct |
24 |
Correct |
4 ms |
564 KB |
Correct |
25 |
Correct |
3 ms |
548 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
344 KB |
Correct |
3 |
Correct |
1 ms |
600 KB |
Correct |
4 |
Correct |
2 ms |
600 KB |
Correct |
5 |
Correct |
2 ms |
428 KB |
Correct |
6 |
Correct |
2 ms |
432 KB |
Correct |
7 |
Correct |
2 ms |
532 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Correct |
2 |
Correct |
1 ms |
344 KB |
Correct |
3 |
Correct |
1 ms |
600 KB |
Correct |
4 |
Correct |
2 ms |
600 KB |
Correct |
5 |
Correct |
2 ms |
428 KB |
Correct |
6 |
Correct |
2 ms |
432 KB |
Correct |
7 |
Correct |
2 ms |
532 KB |
Correct |
8 |
Correct |
0 ms |
344 KB |
Correct |
9 |
Correct |
0 ms |
344 KB |
Correct |
10 |
Correct |
1 ms |
344 KB |
Correct |
11 |
Correct |
1 ms |
344 KB |
Correct |
12 |
Correct |
4 ms |
600 KB |
Correct |
13 |
Correct |
2 ms |
600 KB |
Correct |
14 |
Correct |
3 ms |
600 KB |
Correct |
15 |
Correct |
2 ms |
600 KB |
Correct |
16 |
Correct |
3 ms |
668 KB |
Correct |
17 |
Correct |
2 ms |
584 KB |
Correct |
18 |
Correct |
4 ms |
344 KB |
Correct |
19 |
Correct |
2 ms |
580 KB |
Correct |
20 |
Correct |
2 ms |
344 KB |
Correct |
21 |
Correct |
3 ms |
344 KB |
Correct |
22 |
Correct |
1 ms |
344 KB |
Correct |
23 |
Correct |
1 ms |
344 KB |
Correct |
24 |
Correct |
1 ms |
600 KB |
Correct |
25 |
Correct |
2 ms |
600 KB |
Correct |
26 |
Correct |
4 ms |
424 KB |
Correct |
27 |
Correct |
2 ms |
344 KB |
Correct |
28 |
Correct |
2 ms |
524 KB |
Correct |