Submission #429889

# Submission time Handle Problem Language Result Execution time Memory
429889 2021-06-16T10:16:35 Z dolphingarlic The Collection Game (BOI21_swaps) C++14
100 / 100
8 ms 416 KB
#include "swaps.h"

#include <numeric>
#include <algorithm>

void solve(int N, int V) {
	std::vector<int> ans(N);
	std::iota(ans.begin(), ans.end(), 1);
	int P2 = 1;
	while (P2 < N) P2 <<= 1;
	for (int P = 1; P < P2; P <<= 1)
		for (int k = P; k; k >>= 1) {
			std::vector<std::pair<int, int>> visited;
			for (int j = k % P; j < P2 - k; j += 2 * k)
				for (int i = 0; i < k && i + j + k < N; i++)
					if ((i + j) / (2 * P) == (i + j + k) / (2 * P)) {
						schedule(ans[i + j], ans[i + j + k]);
						visited.push_back({i + j, i + j + k});
					}
			std::vector<int> visit_res = visit();
			for (int i = 0; i < visit_res.size(); i++)
				if (!visit_res[i])
					std::swap(ans[visited[i].first], ans[visited[i].second]);
		}
	answer(ans);
}

Compilation message

swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |    for (int i = 0; i < visit_res.size(); i++)
      |                    ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 256 KB Correct
3 Correct 3 ms 280 KB Correct
4 Correct 6 ms 408 KB Correct
5 Correct 7 ms 292 KB Correct
6 Correct 6 ms 292 KB Correct
7 Correct 8 ms 352 KB Correct
8 Correct 6 ms 332 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 256 KB Correct
3 Correct 3 ms 200 KB Correct
4 Correct 5 ms 288 KB Correct
5 Correct 5 ms 296 KB Correct
6 Correct 5 ms 296 KB Correct
7 Correct 5 ms 296 KB Correct
8 Correct 7 ms 300 KB Correct
9 Correct 7 ms 292 KB Correct
10 Correct 5 ms 288 KB Correct
11 Correct 7 ms 352 KB Correct
12 Correct 5 ms 356 KB Correct
13 Correct 5 ms 296 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 200 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 200 KB Correct
3 Correct 1 ms 200 KB Correct
4 Correct 2 ms 200 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Correct
2 Correct 2 ms 256 KB Correct
3 Correct 4 ms 324 KB Correct
4 Correct 6 ms 340 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Correct
2 Correct 2 ms 256 KB Correct
3 Correct 4 ms 324 KB Correct
4 Correct 6 ms 340 KB Correct
5 Correct 1 ms 256 KB Correct
6 Correct 1 ms 260 KB Correct
7 Correct 4 ms 328 KB Correct
8 Correct 7 ms 312 KB Correct
9 Correct 5 ms 296 KB Correct
10 Correct 6 ms 292 KB Correct
11 Correct 6 ms 292 KB Correct
12 Correct 6 ms 292 KB Correct
13 Correct 1 ms 200 KB Correct
14 Correct 1 ms 276 KB Correct
15 Correct 4 ms 200 KB Correct
16 Correct 5 ms 352 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 4 ms 200 KB Correct
4 Correct 5 ms 296 KB Correct
5 Correct 8 ms 276 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 4 ms 200 KB Correct
4 Correct 5 ms 296 KB Correct
5 Correct 8 ms 276 KB Correct
6 Correct 1 ms 256 KB Correct
7 Correct 1 ms 200 KB Correct
8 Correct 2 ms 344 KB Correct
9 Correct 6 ms 320 KB Correct
10 Correct 6 ms 296 KB Correct
11 Correct 5 ms 340 KB Correct
12 Correct 6 ms 292 KB Correct
13 Correct 6 ms 292 KB Correct
14 Correct 7 ms 292 KB Correct
15 Correct 6 ms 296 KB Correct
16 Correct 5 ms 352 KB Correct
17 Correct 6 ms 416 KB Correct
18 Correct 5 ms 296 KB Correct
19 Correct 0 ms 200 KB Correct
20 Correct 1 ms 200 KB Correct
21 Correct 2 ms 344 KB Correct
22 Correct 6 ms 376 KB Correct
23 Correct 6 ms 292 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 240 KB Correct
3 Correct 3 ms 200 KB Correct
4 Correct 5 ms 296 KB Correct
5 Correct 5 ms 376 KB Correct
6 Correct 5 ms 376 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 240 KB Correct
3 Correct 3 ms 200 KB Correct
4 Correct 5 ms 296 KB Correct
5 Correct 5 ms 376 KB Correct
6 Correct 5 ms 376 KB Correct
7 Correct 1 ms 200 KB Correct
8 Correct 2 ms 200 KB Correct
9 Correct 4 ms 276 KB Correct
10 Correct 5 ms 296 KB Correct
11 Correct 6 ms 296 KB Correct
12 Correct 7 ms 288 KB Correct
13 Correct 6 ms 296 KB Correct
14 Correct 5 ms 288 KB Correct
15 Correct 5 ms 288 KB Correct
16 Correct 4 ms 296 KB Correct
17 Correct 5 ms 292 KB Correct
18 Correct 5 ms 336 KB Correct
19 Correct 6 ms 300 KB Correct
20 Correct 1 ms 200 KB Correct
21 Correct 2 ms 256 KB Correct
22 Correct 2 ms 200 KB Correct
23 Correct 7 ms 364 KB Correct
24 Correct 6 ms 268 KB Correct
25 Correct 7 ms 248 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 200 KB Correct
3 Correct 4 ms 280 KB Correct
4 Correct 7 ms 296 KB Correct
5 Correct 6 ms 272 KB Correct
6 Correct 6 ms 264 KB Correct
7 Correct 6 ms 320 KB Correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Correct
2 Correct 2 ms 200 KB Correct
3 Correct 4 ms 280 KB Correct
4 Correct 7 ms 296 KB Correct
5 Correct 6 ms 272 KB Correct
6 Correct 6 ms 264 KB Correct
7 Correct 6 ms 320 KB Correct
8 Correct 1 ms 200 KB Correct
9 Correct 1 ms 200 KB Correct
10 Correct 1 ms 200 KB Correct
11 Correct 3 ms 288 KB Correct
12 Correct 5 ms 356 KB Correct
13 Correct 8 ms 292 KB Correct
14 Correct 5 ms 296 KB Correct
15 Correct 7 ms 412 KB Correct
16 Correct 6 ms 292 KB Correct
17 Correct 5 ms 292 KB Correct
18 Correct 6 ms 292 KB Correct
19 Correct 7 ms 348 KB Correct
20 Correct 7 ms 300 KB Correct
21 Correct 6 ms 292 KB Correct
22 Correct 1 ms 200 KB Correct
23 Correct 1 ms 200 KB Correct
24 Correct 4 ms 200 KB Correct
25 Correct 6 ms 292 KB Correct
26 Correct 6 ms 268 KB Correct
27 Correct 6 ms 276 KB Correct
28 Correct 6 ms 248 KB Correct