// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
#include "swaps.h"
using namespace std;
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 505;
const int MAXL = 9;
int n, on;
vi p;
vii moves;
void my_schedule(int i, int j) {
cerr << " " << i << ' ' << j << '\n';
moves.pb({i, j});
if (i <= on && j <= on) {
schedule(i, j);
}
}
vi my_visit() {
vi tmp = visit();
reverse(ALL(tmp));
vi res;
for (auto [i, j] : moves) {
if (i <= on && j <= on) {
res.pb(tmp.back());
tmp.pop_back();
} else if (i > on && j > on) {
res.pb(i < j);
} else if (i > on) {
res.pb(0);
} else {
res.pb(1);
}
}
moves.clear();
return res;
}
void solve(int N, int V) {
on = n = N;
p = vi(n, 0);
iota(ALL(p), 1);
while (__builtin_popcount(n) > 1) {
n++;
p.pb(n);
}
REP (k, 0, MAXL) {
cerr << k << '\n';
for (int i = 1; (i << k) < n; i += 2) {
reverse(p.begin() + (i << k), p.begin() + min(i + 1 << k, n));
}
RREP (l, k, 0) {
cerr << ' ' << l << '\n';
vii moves;
REP (i, 0, n) {
if (i >> l & 1) {
int j = i - (1 << l);
my_schedule(p[j], p[i]);
moves.pb({j, i});
}
}
vi res = my_visit();
assert(SZ(res) == SZ(moves));
REP (i, 0, SZ(res)) {
if (!res[i]) {
swap(p[moves[i].FI], p[moves[i].SE]);
}
}
for (int i : p) {
cerr << i << ' ';
}
cerr << '\n';
}
}
p.resize(on);
answer(p);
}
Compilation message
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:82:61: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
82 | reverse(p.begin() + (i << k), p.begin() + min(i + 1 << k, n));
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
208 KB |
Correct |
3 |
Correct |
3 ms |
208 KB |
Correct |
4 |
Correct |
5 ms |
320 KB |
Correct |
5 |
Correct |
5 ms |
320 KB |
Correct |
6 |
Correct |
5 ms |
312 KB |
Correct |
7 |
Correct |
4 ms |
316 KB |
Correct |
8 |
Correct |
5 ms |
312 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
2 ms |
208 KB |
Correct |
3 |
Correct |
2 ms |
208 KB |
Correct |
4 |
Correct |
5 ms |
320 KB |
Correct |
5 |
Correct |
4 ms |
312 KB |
Correct |
6 |
Correct |
5 ms |
320 KB |
Correct |
7 |
Correct |
4 ms |
316 KB |
Correct |
8 |
Correct |
5 ms |
316 KB |
Correct |
9 |
Correct |
5 ms |
320 KB |
Correct |
10 |
Correct |
5 ms |
324 KB |
Correct |
11 |
Correct |
5 ms |
312 KB |
Correct |
12 |
Correct |
6 ms |
552 KB |
Correct |
13 |
Correct |
4 ms |
316 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
288 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
288 KB |
Correct |
3 |
Correct |
1 ms |
208 KB |
Correct |
4 |
Correct |
2 ms |
208 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
2 ms |
208 KB |
Correct |
3 |
Correct |
3 ms |
348 KB |
Correct |
4 |
Correct |
5 ms |
316 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
2 ms |
208 KB |
Correct |
3 |
Correct |
3 ms |
348 KB |
Correct |
4 |
Correct |
5 ms |
316 KB |
Correct |
5 |
Correct |
2 ms |
208 KB |
Correct |
6 |
Correct |
2 ms |
208 KB |
Correct |
7 |
Correct |
2 ms |
208 KB |
Correct |
8 |
Correct |
5 ms |
320 KB |
Correct |
9 |
Correct |
5 ms |
312 KB |
Correct |
10 |
Correct |
5 ms |
312 KB |
Correct |
11 |
Correct |
6 ms |
316 KB |
Correct |
12 |
Correct |
6 ms |
312 KB |
Correct |
13 |
Correct |
1 ms |
208 KB |
Correct |
14 |
Correct |
2 ms |
288 KB |
Correct |
15 |
Correct |
3 ms |
208 KB |
Correct |
16 |
Correct |
4 ms |
316 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
2 ms |
208 KB |
Correct |
3 |
Correct |
2 ms |
208 KB |
Correct |
4 |
Correct |
5 ms |
360 KB |
Correct |
5 |
Correct |
4 ms |
296 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
2 ms |
208 KB |
Correct |
3 |
Correct |
2 ms |
208 KB |
Correct |
4 |
Correct |
5 ms |
360 KB |
Correct |
5 |
Correct |
4 ms |
296 KB |
Correct |
6 |
Correct |
1 ms |
208 KB |
Correct |
7 |
Correct |
2 ms |
208 KB |
Correct |
8 |
Correct |
3 ms |
208 KB |
Correct |
9 |
Correct |
4 ms |
316 KB |
Correct |
10 |
Correct |
5 ms |
320 KB |
Correct |
11 |
Correct |
5 ms |
316 KB |
Correct |
12 |
Correct |
4 ms |
320 KB |
Correct |
13 |
Correct |
5 ms |
312 KB |
Correct |
14 |
Correct |
5 ms |
320 KB |
Correct |
15 |
Correct |
5 ms |
312 KB |
Correct |
16 |
Correct |
4 ms |
316 KB |
Correct |
17 |
Correct |
4 ms |
332 KB |
Correct |
18 |
Correct |
4 ms |
312 KB |
Correct |
19 |
Correct |
1 ms |
208 KB |
Correct |
20 |
Correct |
2 ms |
208 KB |
Correct |
21 |
Correct |
3 ms |
208 KB |
Correct |
22 |
Correct |
5 ms |
316 KB |
Correct |
23 |
Correct |
5 ms |
296 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
208 KB |
Correct |
3 |
Correct |
2 ms |
208 KB |
Correct |
4 |
Correct |
5 ms |
312 KB |
Correct |
5 |
Correct |
5 ms |
316 KB |
Correct |
6 |
Correct |
4 ms |
292 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
208 KB |
Correct |
3 |
Correct |
2 ms |
208 KB |
Correct |
4 |
Correct |
5 ms |
312 KB |
Correct |
5 |
Correct |
5 ms |
316 KB |
Correct |
6 |
Correct |
4 ms |
292 KB |
Correct |
7 |
Correct |
1 ms |
208 KB |
Correct |
8 |
Correct |
2 ms |
208 KB |
Correct |
9 |
Correct |
3 ms |
208 KB |
Correct |
10 |
Correct |
6 ms |
312 KB |
Correct |
11 |
Correct |
5 ms |
312 KB |
Correct |
12 |
Correct |
7 ms |
312 KB |
Correct |
13 |
Correct |
5 ms |
320 KB |
Correct |
14 |
Correct |
4 ms |
312 KB |
Correct |
15 |
Correct |
5 ms |
312 KB |
Correct |
16 |
Correct |
4 ms |
312 KB |
Correct |
17 |
Correct |
4 ms |
312 KB |
Correct |
18 |
Correct |
6 ms |
316 KB |
Correct |
19 |
Correct |
5 ms |
320 KB |
Correct |
20 |
Correct |
0 ms |
208 KB |
Correct |
21 |
Correct |
2 ms |
288 KB |
Correct |
22 |
Correct |
2 ms |
208 KB |
Correct |
23 |
Correct |
5 ms |
424 KB |
Correct |
24 |
Correct |
5 ms |
312 KB |
Correct |
25 |
Correct |
4 ms |
300 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
2 ms |
208 KB |
Correct |
3 |
Correct |
3 ms |
208 KB |
Correct |
4 |
Correct |
4 ms |
316 KB |
Correct |
5 |
Correct |
4 ms |
320 KB |
Correct |
6 |
Correct |
6 ms |
292 KB |
Correct |
7 |
Correct |
6 ms |
300 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
2 ms |
208 KB |
Correct |
3 |
Correct |
3 ms |
208 KB |
Correct |
4 |
Correct |
4 ms |
316 KB |
Correct |
5 |
Correct |
4 ms |
320 KB |
Correct |
6 |
Correct |
6 ms |
292 KB |
Correct |
7 |
Correct |
6 ms |
300 KB |
Correct |
8 |
Correct |
1 ms |
208 KB |
Correct |
9 |
Correct |
1 ms |
208 KB |
Correct |
10 |
Correct |
2 ms |
208 KB |
Correct |
11 |
Correct |
3 ms |
208 KB |
Correct |
12 |
Correct |
5 ms |
312 KB |
Correct |
13 |
Correct |
5 ms |
308 KB |
Correct |
14 |
Correct |
4 ms |
312 KB |
Correct |
15 |
Correct |
4 ms |
320 KB |
Correct |
16 |
Correct |
6 ms |
416 KB |
Correct |
17 |
Correct |
4 ms |
316 KB |
Correct |
18 |
Correct |
6 ms |
312 KB |
Correct |
19 |
Correct |
5 ms |
312 KB |
Correct |
20 |
Correct |
6 ms |
320 KB |
Correct |
21 |
Correct |
4 ms |
312 KB |
Correct |
22 |
Correct |
1 ms |
208 KB |
Correct |
23 |
Correct |
2 ms |
288 KB |
Correct |
24 |
Correct |
4 ms |
208 KB |
Correct |
25 |
Correct |
6 ms |
316 KB |
Correct |
26 |
Correct |
5 ms |
292 KB |
Correct |
27 |
Correct |
5 ms |
296 KB |
Correct |
28 |
Correct |
5 ms |
300 KB |
Correct |