답안 #905289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
905289 2024-01-12T22:31:30 Z MinaRagy06 The Collection Game (BOI21_swaps) C++17
100 / 100
6 ms 1536 KB
#include <bits/stdc++.h>
#include "swaps.h"
#ifdef MINA
#include "grader.cpp"
#endif
using namespace std;
typedef int64_t ll;

const int MAXN = 50;
vector<array<int, 2>> ops[MAXN];
int sz, n;
int bitonic(int l, int r, bool inc, int lvl, bool isbitonic) {
	if (l == r) {
		return lvl - 1;
	}
	int md = (l + r) >> 1, mx = lvl - 1;
	if (!isbitonic) {
		mx = bitonic(l, md, inc, lvl, 0);
		bitonic(md + 1, r, !inc, lvl, 0);
	}
	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 + 2, 1);
	return bitonic(md + 1, r, inc, mx + 2, 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, 0, 0);
	assert(dep < MAXN);
	for (int j = 0; j < MAXN; 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:68:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   68 |  while (a.size() > n) a.pop_back();
      |         ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 2 ms 484 KB Correct
4 Correct 5 ms 1536 KB Correct
5 Correct 4 ms 552 KB Correct
6 Correct 4 ms 552 KB Correct
7 Correct 4 ms 796 KB Correct
8 Correct 4 ms 544 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 2 ms 488 KB Correct
4 Correct 5 ms 800 KB Correct
5 Correct 4 ms 548 KB Correct
6 Correct 4 ms 800 KB Correct
7 Correct 4 ms 1052 KB Correct
8 Correct 4 ms 1052 KB Correct
9 Correct 4 ms 600 KB Correct
10 Correct 4 ms 548 KB Correct
11 Correct 5 ms 552 KB Correct
12 Correct 4 ms 552 KB Correct
13 Correct 4 ms 800 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 344 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 1 ms 344 KB Correct
4 Correct 1 ms 344 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 2 ms 488 KB Correct
4 Correct 4 ms 548 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 2 ms 488 KB Correct
4 Correct 4 ms 548 KB Correct
5 Correct 1 ms 344 KB Correct
6 Correct 1 ms 344 KB Correct
7 Correct 2 ms 488 KB Correct
8 Correct 4 ms 796 KB Correct
9 Correct 4 ms 800 KB Correct
10 Correct 4 ms 548 KB Correct
11 Correct 4 ms 552 KB Correct
12 Correct 4 ms 552 KB Correct
13 Correct 1 ms 344 KB Correct
14 Correct 1 ms 344 KB Correct
15 Correct 2 ms 600 KB Correct
16 Correct 5 ms 804 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 2 ms 488 KB Correct
4 Correct 4 ms 792 KB Correct
5 Correct 4 ms 804 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 2 ms 488 KB Correct
4 Correct 4 ms 792 KB Correct
5 Correct 4 ms 804 KB Correct
6 Correct 1 ms 344 KB Correct
7 Correct 1 ms 344 KB Correct
8 Correct 2 ms 488 KB Correct
9 Correct 4 ms 556 KB Correct
10 Correct 4 ms 804 KB Correct
11 Correct 4 ms 800 KB Correct
12 Correct 4 ms 552 KB Correct
13 Correct 4 ms 804 KB Correct
14 Correct 4 ms 800 KB Correct
15 Correct 4 ms 556 KB Correct
16 Correct 4 ms 800 KB Correct
17 Correct 4 ms 548 KB Correct
18 Correct 4 ms 808 KB Correct
19 Correct 1 ms 344 KB Correct
20 Correct 1 ms 344 KB Correct
21 Correct 2 ms 488 KB Correct
22 Correct 4 ms 804 KB Correct
23 Correct 4 ms 560 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 2 ms 344 KB Correct
3 Correct 2 ms 488 KB Correct
4 Correct 4 ms 548 KB Correct
5 Correct 4 ms 808 KB Correct
6 Correct 5 ms 756 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 2 ms 344 KB Correct
3 Correct 2 ms 488 KB Correct
4 Correct 4 ms 548 KB Correct
5 Correct 4 ms 808 KB Correct
6 Correct 5 ms 756 KB Correct
7 Correct 1 ms 344 KB Correct
8 Correct 1 ms 344 KB Correct
9 Correct 2 ms 484 KB Correct
10 Correct 4 ms 804 KB Correct
11 Correct 4 ms 796 KB Correct
12 Correct 4 ms 548 KB Correct
13 Correct 4 ms 548 KB Correct
14 Correct 4 ms 556 KB Correct
15 Correct 4 ms 556 KB Correct
16 Correct 4 ms 800 KB Correct
17 Correct 4 ms 552 KB Correct
18 Correct 4 ms 552 KB Correct
19 Correct 4 ms 1052 KB Correct
20 Correct 0 ms 344 KB Correct
21 Correct 1 ms 344 KB Correct
22 Correct 2 ms 484 KB Correct
23 Correct 4 ms 552 KB Correct
24 Correct 4 ms 552 KB Correct
25 Correct 5 ms 592 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 2 ms 484 KB Correct
4 Correct 4 ms 808 KB Correct
5 Correct 5 ms 804 KB Correct
6 Correct 5 ms 548 KB Correct
7 Correct 4 ms 712 KB Correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Correct
2 Correct 1 ms 344 KB Correct
3 Correct 2 ms 484 KB Correct
4 Correct 4 ms 808 KB Correct
5 Correct 5 ms 804 KB Correct
6 Correct 5 ms 548 KB Correct
7 Correct 4 ms 712 KB Correct
8 Correct 1 ms 344 KB Correct
9 Correct 1 ms 344 KB Correct
10 Correct 1 ms 344 KB Correct
11 Correct 2 ms 484 KB Correct
12 Correct 4 ms 800 KB Correct
13 Correct 6 ms 1056 KB Correct
14 Correct 4 ms 552 KB Correct
15 Correct 4 ms 564 KB Correct
16 Correct 4 ms 1052 KB Correct
17 Correct 4 ms 556 KB Correct
18 Correct 5 ms 556 KB Correct
19 Correct 5 ms 1056 KB Correct
20 Correct 4 ms 548 KB Correct
21 Correct 5 ms 800 KB Correct
22 Correct 1 ms 344 KB Correct
23 Correct 1 ms 600 KB Correct
24 Correct 2 ms 484 KB Correct
25 Correct 4 ms 792 KB Correct
26 Correct 4 ms 720 KB Correct
27 Correct 4 ms 552 KB Correct
28 Correct 4 ms 532 KB Correct