답안 #1014363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1014363 2024-07-04T18:56:45 Z EntityPlantt Xor Sort (eJOI20_xorsort) C++17
100 / 100
5 ms 1192 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 1005;
int arr[N], elms[N];
vector <pair <int, int>> oper;

void makexor(int a, int b, bool change = true) {
	if (change) arr[a] = arr[a] ^ arr[b];
	if (!oper.empty() && oper.back() == pair{a, b}) oper.pop_back();
	else oper.emplace_back(a, b);
}
void fixzeroes(int nowat) {
	for (int i = 1; i < nowat; i++) {
		if (arr[i - 1] && !arr[i]) makexor(i, i - 1);
	}
}

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	char s;
	cin >> n >> s;
	for (int i = 0; i < n; i++) cin >> arr[i];
	if (s == '2') {
		int nowat = n;
		while (true) {
			int largestBit = 0;
			for (int i = 0; i < nowat; i++) {
				if ((1 << largestBit) <= arr[i]) {
					while ((1 << largestBit) <= arr[i]) largestBit++;
					largestBit--;
				}
			}
			if (!largestBit) break;
			nowat--;
			for (int i = 0; i < nowat; i++) {
				if ((1 << largestBit) & arr[i]) {
					if (!((1 << largestBit) & arr[i + 1])) makexor(i + 1, i);
					makexor(i, i + 1);
				}
			}
		}
		fixzeroes(nowat);
	}
	else {
		copy(arr, arr + n, elms);
		for (int i = 1; i < n; i++) makexor(i - 1, i);
		for (int i = n - 1; i; i--) {
			int x = distance(elms, max_element(elms, elms + i + 1));
			for (int j = x; j < i; j++) makexor(j + 1, j);
			for (int j = max(x - 1, 0); j < i; j++) makexor(j, j + 1);
			for (int j = x; j < i; j++) swap(elms[j], elms[j + 1]);
		}
		// for (int i = 0; i < n; i++) cerr << arr[i] << ' ';
	}
	cout << oper.size();
	for (auto &p : oper) cout << '\n' << p.first + 1 << ' ' << p.second + 1;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 3 ms 736 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 3 ms 736 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Correct 2 ms 860 KB Output is correct
15 Correct 3 ms 860 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 3 ms 844 KB Output is correct
19 Correct 3 ms 860 KB Output is correct
20 Correct 2 ms 860 KB Output is correct
21 Correct 2 ms 736 KB Output is correct
22 Correct 2 ms 856 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 2 ms 736 KB Output is correct
25 Correct 2 ms 856 KB Output is correct
26 Correct 5 ms 992 KB Output is correct
27 Correct 5 ms 992 KB Output is correct
28 Correct 4 ms 992 KB Output is correct
29 Correct 5 ms 992 KB Output is correct
30 Correct 4 ms 992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 3 ms 992 KB Output is correct
6 Correct 3 ms 992 KB Output is correct
7 Correct 4 ms 992 KB Output is correct
8 Correct 3 ms 992 KB Output is correct
9 Correct 3 ms 992 KB Output is correct
10 Correct 3 ms 984 KB Output is correct
11 Correct 3 ms 988 KB Output is correct
12 Correct 4 ms 992 KB Output is correct
13 Correct 3 ms 992 KB Output is correct
14 Correct 5 ms 992 KB Output is correct
15 Correct 4 ms 1192 KB Output is correct