답안 #1070294

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070294 2024-08-22T12:53:57 Z AdamGS Xor Sort (eJOI20_xorsort) C++17
100 / 100
7 ms 1100 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e3+7;
int T[LIM], n;
vector<pair<int,int>>V;
void solve1() {
	rep(i, n-1) V.pb({i+1, i});
	rep(i, n) for(int j=i; j>0; --j) if(T[j-1]>T[j]) {
		V.pb({j-1, j});
		if(j-1>0) V.pb({j-1, j-2});
		swap(T[j], T[j-1]);
	}
	for(int i=n-2; i>=0; --i) V.pb({i+1, i});
}
void solve2() {
	for(int i=19; i>=0; --i) {
		rep(j, n-1) {
			if(T[j+1]>=(1<<(i+1))) break;
			if(!(T[j]&(1<<i))) continue;
			if(!(T[j+1]&(1<<i))) {
				V.pb({j+1, j});
				T[j+1]^=T[j];
			}
			V.pb({j, j+1});
			T[j]^=T[j+1];
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int s;
	cin >> n >> s;
	rep(i, n) cin >> T[i];
	if(s==1) solve1();
	else solve2();
	cout << V.size() << '\n';
	for(auto i : V) cout << i.st+1 << " " << i.nd+1 << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 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 708 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 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 868 KB Output is correct
13 Correct 3 ms 736 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 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 708 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 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 868 KB Output is correct
13 Correct 3 ms 736 KB Output is correct
14 Correct 3 ms 860 KB Output is correct
15 Correct 3 ms 736 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 2 ms 600 KB Output is correct
18 Correct 3 ms 860 KB Output is correct
19 Correct 3 ms 732 KB Output is correct
20 Correct 3 ms 860 KB Output is correct
21 Correct 3 ms 856 KB Output is correct
22 Correct 3 ms 736 KB Output is correct
23 Correct 2 ms 736 KB Output is correct
24 Correct 3 ms 860 KB Output is correct
25 Correct 3 ms 736 KB Output is correct
26 Correct 5 ms 992 KB Output is correct
27 Correct 5 ms 992 KB Output is correct
28 Correct 5 ms 992 KB Output is correct
29 Correct 5 ms 1100 KB Output is correct
30 Correct 5 ms 992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 4 ms 988 KB Output is correct
6 Correct 4 ms 992 KB Output is correct
7 Correct 4 ms 992 KB Output is correct
8 Correct 7 ms 992 KB Output is correct
9 Correct 4 ms 992 KB Output is correct
10 Correct 5 ms 988 KB Output is correct
11 Correct 3 ms 992 KB Output is correct
12 Correct 4 ms 932 KB Output is correct
13 Correct 7 ms 992 KB Output is correct
14 Correct 7 ms 992 KB Output is correct
15 Correct 5 ms 988 KB Output is correct