//
// --- 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;
#define ll long long
#define pii pair<int, int>
#define vb vector<bool>
#define vi vector<int>
#define vpii vector<pii>
#define vvb vector<vb>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vvpii vector<vpii>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
int N, V;
int nextN;
void genMerge(int level, vvpii &res)
{
// 2 times initial length = 1 << level ⇒ 1 << (level + 1)
int len = 1 << level;
int tot = 1 << (level + 1);
res.clear();
while (len >= 1)
{
res.push_back(vpii());
for (int i = len; i < tot; i += 2 * len)
for (int j = 0; j < len; ++j)
{
int a = (i + j) % tot, b = (i + j + len) % tot;
res.back().push_back({min(a, b), max(a, b)});
}
len >>= 1;
}
}
void solve(int _N, int _V)
{
N = _N, V = _V;
nextN = 1;
while (nextN < N)
nextN *= 2;
if (N == 1)
{
answer({1});
return;
}
vi A(nextN);
iota(all(A), 1);
vvpii pattern;
for (int pot = 0; (1 << pot) < nextN; ++pot)
{
genMerge(pot, pattern);
for (int j = 0; j < sz(pattern); ++j)
{
for (int i = 0; i < N; i += 1 << (pot + 1))
for (pii tmp : pattern[j])
if (A[i + tmp.first] <= N && A[i + tmp.second] <= N)
schedule(A[i + tmp.first], A[i + tmp.second]);
vi ans = visit();
int idx = 0;
for (int i = 0; i < N; i += 1 << (pot + 1))
for (pii tmp : pattern[j])
if (A[i + tmp.first] <= N && A[i + tmp.second] <= N)
if (!ans[idx++])
swap(A[i + tmp.first], A[i + tmp.second]);
}
}
while (sz(A) > N)
A.pop_back();
answer(A);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
260 KB |
Correct |
3 |
Correct |
2 ms |
208 KB |
Correct |
4 |
Correct |
4 ms |
312 KB |
Correct |
5 |
Correct |
4 ms |
336 KB |
Correct |
6 |
Correct |
4 ms |
332 KB |
Correct |
7 |
Correct |
4 ms |
324 KB |
Correct |
8 |
Correct |
6 ms |
332 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 |
4 ms |
320 KB |
Correct |
5 |
Correct |
4 ms |
324 KB |
Correct |
6 |
Correct |
4 ms |
440 KB |
Correct |
7 |
Correct |
4 ms |
332 KB |
Correct |
8 |
Correct |
4 ms |
320 KB |
Correct |
9 |
Correct |
4 ms |
308 KB |
Correct |
10 |
Correct |
5 ms |
340 KB |
Correct |
11 |
Correct |
4 ms |
332 KB |
Correct |
12 |
Correct |
4 ms |
328 KB |
Correct |
13 |
Correct |
6 ms |
332 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
208 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
208 KB |
Correct |
3 |
Correct |
1 ms |
208 KB |
Correct |
4 |
Correct |
1 ms |
304 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
296 KB |
Correct |
3 |
Correct |
2 ms |
208 KB |
Correct |
4 |
Correct |
4 ms |
336 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
296 KB |
Correct |
3 |
Correct |
2 ms |
208 KB |
Correct |
4 |
Correct |
4 ms |
336 KB |
Correct |
5 |
Correct |
1 ms |
208 KB |
Correct |
6 |
Correct |
1 ms |
304 KB |
Correct |
7 |
Correct |
2 ms |
208 KB |
Correct |
8 |
Correct |
5 ms |
320 KB |
Correct |
9 |
Correct |
5 ms |
316 KB |
Correct |
10 |
Correct |
4 ms |
336 KB |
Correct |
11 |
Correct |
6 ms |
340 KB |
Correct |
12 |
Correct |
5 ms |
340 KB |
Correct |
13 |
Correct |
1 ms |
208 KB |
Correct |
14 |
Correct |
1 ms |
208 KB |
Correct |
15 |
Correct |
2 ms |
208 KB |
Correct |
16 |
Correct |
4 ms |
308 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 |
4 ms |
320 KB |
Correct |
5 |
Correct |
4 ms |
308 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 |
4 ms |
320 KB |
Correct |
5 |
Correct |
4 ms |
308 KB |
Correct |
6 |
Correct |
1 ms |
208 KB |
Correct |
7 |
Correct |
1 ms |
208 KB |
Correct |
8 |
Correct |
2 ms |
208 KB |
Correct |
9 |
Correct |
4 ms |
308 KB |
Correct |
10 |
Correct |
5 ms |
304 KB |
Correct |
11 |
Correct |
6 ms |
320 KB |
Correct |
12 |
Correct |
6 ms |
332 KB |
Correct |
13 |
Correct |
6 ms |
336 KB |
Correct |
14 |
Correct |
4 ms |
340 KB |
Correct |
15 |
Correct |
4 ms |
304 KB |
Correct |
16 |
Correct |
4 ms |
320 KB |
Correct |
17 |
Correct |
4 ms |
332 KB |
Correct |
18 |
Correct |
4 ms |
332 KB |
Correct |
19 |
Correct |
0 ms |
208 KB |
Correct |
20 |
Correct |
1 ms |
208 KB |
Correct |
21 |
Correct |
2 ms |
208 KB |
Correct |
22 |
Correct |
5 ms |
316 KB |
Correct |
23 |
Correct |
5 ms |
300 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
208 KB |
Correct |
3 |
Correct |
3 ms |
208 KB |
Correct |
4 |
Correct |
4 ms |
324 KB |
Correct |
5 |
Correct |
7 ms |
296 KB |
Correct |
6 |
Correct |
4 ms |
292 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
208 KB |
Correct |
3 |
Correct |
3 ms |
208 KB |
Correct |
4 |
Correct |
4 ms |
324 KB |
Correct |
5 |
Correct |
7 ms |
296 KB |
Correct |
6 |
Correct |
4 ms |
292 KB |
Correct |
7 |
Correct |
0 ms |
208 KB |
Correct |
8 |
Correct |
1 ms |
208 KB |
Correct |
9 |
Correct |
2 ms |
208 KB |
Correct |
10 |
Correct |
6 ms |
308 KB |
Correct |
11 |
Correct |
4 ms |
336 KB |
Correct |
12 |
Correct |
6 ms |
316 KB |
Correct |
13 |
Correct |
4 ms |
320 KB |
Correct |
14 |
Correct |
4 ms |
328 KB |
Correct |
15 |
Correct |
5 ms |
332 KB |
Correct |
16 |
Correct |
4 ms |
332 KB |
Correct |
17 |
Correct |
4 ms |
340 KB |
Correct |
18 |
Correct |
4 ms |
320 KB |
Correct |
19 |
Correct |
5 ms |
312 KB |
Correct |
20 |
Correct |
1 ms |
208 KB |
Correct |
21 |
Correct |
1 ms |
208 KB |
Correct |
22 |
Correct |
3 ms |
336 KB |
Correct |
23 |
Correct |
5 ms |
292 KB |
Correct |
24 |
Correct |
5 ms |
436 KB |
Correct |
25 |
Correct |
4 ms |
300 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
208 KB |
Correct |
3 |
Correct |
2 ms |
304 KB |
Correct |
4 |
Correct |
5 ms |
316 KB |
Correct |
5 |
Correct |
4 ms |
300 KB |
Correct |
6 |
Correct |
4 ms |
312 KB |
Correct |
7 |
Correct |
5 ms |
288 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Correct |
2 |
Correct |
1 ms |
208 KB |
Correct |
3 |
Correct |
2 ms |
304 KB |
Correct |
4 |
Correct |
5 ms |
316 KB |
Correct |
5 |
Correct |
4 ms |
300 KB |
Correct |
6 |
Correct |
4 ms |
312 KB |
Correct |
7 |
Correct |
5 ms |
288 KB |
Correct |
8 |
Correct |
1 ms |
208 KB |
Correct |
9 |
Correct |
1 ms |
208 KB |
Correct |
10 |
Correct |
1 ms |
208 KB |
Correct |
11 |
Correct |
3 ms |
208 KB |
Correct |
12 |
Correct |
4 ms |
320 KB |
Correct |
13 |
Correct |
4 ms |
340 KB |
Correct |
14 |
Correct |
4 ms |
360 KB |
Correct |
15 |
Correct |
6 ms |
316 KB |
Correct |
16 |
Correct |
6 ms |
320 KB |
Correct |
17 |
Correct |
4 ms |
320 KB |
Correct |
18 |
Correct |
6 ms |
336 KB |
Correct |
19 |
Correct |
4 ms |
324 KB |
Correct |
20 |
Correct |
4 ms |
308 KB |
Correct |
21 |
Correct |
4 ms |
320 KB |
Correct |
22 |
Correct |
0 ms |
208 KB |
Correct |
23 |
Correct |
1 ms |
208 KB |
Correct |
24 |
Correct |
2 ms |
300 KB |
Correct |
25 |
Correct |
4 ms |
304 KB |
Correct |
26 |
Correct |
4 ms |
312 KB |
Correct |
27 |
Correct |
6 ms |
288 KB |
Correct |
28 |
Correct |
6 ms |
404 KB |
Correct |