#include <bits/stdc++.h>
#include "swaps.h"
#ifdef MINA
#include "grader.cpp"
#endif
using namespace std;
typedef int64_t ll;
const int N = 500;
vector<array<int, 2>> ops[N];
int sz, n;
int bitonic(int l, int r, bool inc, int lvl) {
if (l == r) {
return lvl;
}
int md = (l + r) >> 1, mx;
mx = bitonic(l, md, inc, lvl);
bitonic(md + 1, r, !inc, lvl);
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 + 1);
return bitonic(md + 1, r, inc, mx + 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, -1);
assert(dep < N);
for (int j = 0; j < N; 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:66:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
66 | while (a.size() > n) a.pop_back();
| ~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
596 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |