#include <bits/stdc++.h>
#include "swaps.h"
template <class T> using Vec = std::vector<T>;
void solve(int N, int V) {
if (V == 5000) {
Vec<char> done(N);
Vec<int> ans;
while (true) {
Vec<int> remain;
for (int i = 0; i < N; ++i) {
if (!done[i]) {
remain.push_back(i);
}
}
if (remain.empty()) {
break;
}
while (remain.size() > 1) {
Vec<int> next;
Vec<std::array<int, 2>> ask;
for (int i = 0; i + 1 < (int) remain.size(); i += 2) {
schedule(remain[i] + 1, remain[i + 1] + 1);
ask.push_back({remain[i + 1], remain[i]});
}
const auto ret = visit();
for (int i = 0; i < (int) ret.size(); ++i) {
next.push_back(ask[i][ret[i]]);
}
if (remain.size() % 2 == 1) {
next.push_back(remain.back());
}
remain = std::move(next);
}
done[remain[0]] = true;
ans.push_back(remain[0] + 1);
}
answer(ans);
} else {
Vec<std::queue<int>> cur(N);
for (int i = 0; i < N; ++i) {
cur[i].push(i + 1);
}
while (cur.size() > 1) {
Vec<std::queue<int>> next(cur.size() / 2);
if (cur.size() % 2 == 1) {
next.push_back(cur.back());
cur.pop_back();
}
const int size = (int) cur.size() / 2;
while (true) {
Vec<int> ask;
for (int i = 0; i < size; ++i) {
const int l = 2 * i;
const int r = 2 * i + 1;
if (cur[l].empty()) {
std::swap(cur[l], cur[r]);
}
if (cur[r].empty()) {
while (!cur[l].empty()) {
next[i].push(cur[l].front());
cur[l].pop();
}
} else {
schedule(cur[l].front(), cur[r].front());
ask.emplace_back(i);
}
}
if (ask.empty()) {
break;
}
const auto ret = visit();
for (int i = 0; i < (int) ret.size(); ++i) {
const auto k = ask[i];
const auto idx = 2 * k + 1 - ret[i];
next[k].push(cur[idx].front());
cur[idx].pop();
}
}
cur = std::move(next);
}
Vec<int> ans;
while (!cur[0].empty()) {
ans.push_back(cur[0].front());
cur[0].pop();
}
answer(ans);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
10 ms |
308 KB |
Correct |
3 |
Correct |
36 ms |
284 KB |
Correct |
4 |
Correct |
129 ms |
312 KB |
Correct |
5 |
Correct |
118 ms |
312 KB |
Correct |
6 |
Correct |
113 ms |
312 KB |
Correct |
7 |
Correct |
120 ms |
300 KB |
Correct |
8 |
Correct |
106 ms |
304 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
13 ms |
200 KB |
Correct |
3 |
Correct |
31 ms |
292 KB |
Correct |
4 |
Correct |
85 ms |
300 KB |
Correct |
5 |
Correct |
82 ms |
308 KB |
Correct |
6 |
Correct |
105 ms |
312 KB |
Correct |
7 |
Correct |
111 ms |
304 KB |
Correct |
8 |
Correct |
122 ms |
308 KB |
Correct |
9 |
Correct |
20 ms |
712 KB |
Correct |
10 |
Correct |
10 ms |
712 KB |
Correct |
11 |
Correct |
9 ms |
712 KB |
Correct |
12 |
Runtime error |
20 ms |
712 KB |
Execution killed with signal 13 |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
10 ms |
200 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
10 ms |
200 KB |
Correct |
3 |
Correct |
2 ms |
200 KB |
Correct |
4 |
Correct |
13 ms |
200 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Correct |
2 |
Correct |
9 ms |
200 KB |
Correct |
3 |
Correct |
23 ms |
300 KB |
Correct |
4 |
Correct |
104 ms |
308 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Correct |
2 |
Correct |
9 ms |
200 KB |
Correct |
3 |
Correct |
23 ms |
300 KB |
Correct |
4 |
Correct |
104 ms |
308 KB |
Correct |
5 |
Correct |
1 ms |
200 KB |
Correct |
6 |
Correct |
11 ms |
200 KB |
Correct |
7 |
Correct |
39 ms |
284 KB |
Correct |
8 |
Correct |
135 ms |
308 KB |
Correct |
9 |
Correct |
108 ms |
308 KB |
Correct |
10 |
Correct |
108 ms |
308 KB |
Correct |
11 |
Correct |
101 ms |
308 KB |
Correct |
12 |
Correct |
117 ms |
308 KB |
Correct |
13 |
Correct |
1 ms |
200 KB |
Correct |
14 |
Correct |
11 ms |
200 KB |
Correct |
15 |
Correct |
32 ms |
200 KB |
Correct |
16 |
Correct |
109 ms |
312 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Correct |
2 |
Correct |
9 ms |
200 KB |
Correct |
3 |
Correct |
38 ms |
300 KB |
Correct |
4 |
Correct |
111 ms |
300 KB |
Correct |
5 |
Runtime error |
9 ms |
660 KB |
Execution killed with signal 13 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Correct |
2 |
Correct |
9 ms |
200 KB |
Correct |
3 |
Correct |
38 ms |
300 KB |
Correct |
4 |
Correct |
111 ms |
300 KB |
Correct |
5 |
Runtime error |
9 ms |
660 KB |
Execution killed with signal 13 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
7 ms |
200 KB |
Correct |
3 |
Correct |
26 ms |
304 KB |
Correct |
4 |
Correct |
84 ms |
312 KB |
Correct |
5 |
Runtime error |
6 ms |
660 KB |
Execution killed with signal 13 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
7 ms |
200 KB |
Correct |
3 |
Correct |
26 ms |
304 KB |
Correct |
4 |
Correct |
84 ms |
312 KB |
Correct |
5 |
Runtime error |
6 ms |
660 KB |
Execution killed with signal 13 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
12 ms |
200 KB |
Correct |
3 |
Correct |
37 ms |
284 KB |
Correct |
4 |
Correct |
106 ms |
288 KB |
Correct |
5 |
Runtime error |
6 ms |
660 KB |
Execution killed with signal 13 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
12 ms |
200 KB |
Correct |
3 |
Correct |
37 ms |
284 KB |
Correct |
4 |
Correct |
106 ms |
288 KB |
Correct |
5 |
Runtime error |
6 ms |
660 KB |
Execution killed with signal 13 |
6 |
Halted |
0 ms |
0 KB |
- |