Submission #826711

# Submission time Handle Problem Language Result Execution time Memory
826711 2023-08-15T22:21:32 Z ZeroCool Xor Sort (eJOI20_xorsort) C++14
100 / 100
45 ms 1484 KB
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
using namespace std;
 
const int mxn = 1005;
const int SQRT = 500;
const int LOG = 20;
const int inf = 1e18;
const int mod = 998244353;
const ld eps = 1e-9;

int n;
int A[mxn];

vector<pair<int,int> >res;

void op(int a,int b){
	res.push_back({a+1,b+1});
	A[a] ^= A[b];
}

inline bool bit(int x,int i){
	return x & (1 << i);
}

void s1(){
	int B[n];
	for(int i = 0;i<n;i++)B[i] = A[i];

	for(int i = 0;i<n-1;i++)op(i,i + 1);

	for(int i = n-1;i>=0;i--){
		int k = 0;
		for(int j = 1;j<=i;j++){
			if(B[j] > B[k])k = j;
		}
		for(int j = k+1;j<=i;j++)op(j,j-1);
		for(int j = k-1;j<i;j++){
			if(j != -1)op(j,j+1);
		}

		for(int j = k;j<i;j++)swap(B[j], B[j+1]);
	}
}

void s2(){
	int last = n;
	for (int i = LOG-1; i >= 0; i--){
		bool ok = false;
		for (int j = 0; j < n; j++)
			if (bit(A[j], i)){
				ok = true;
				break;
			}
		if (!ok) continue;
		last--;
		for (int j = 0; j < last; j++)
			if (bit(A[j], i) && !bit(A[j+1], i)){
				op(j+1, j);
				op(j, j+1);
			}
			else if (bit(A[j], i) && bit(A[j+1], i)){
				op(j, j+1);
			}
	}
}

void solve(int T){
	cin>>n;
	int s;
	cin>>s;
	for(int i = 0;i<n;i++)cin>>A[i];

	if(s == 1)s1();
	else s2();

	cout<<res.size()<<endl;
	for(auto p : res)cout<<p.first<<" "<<p.second<<endl;

}
int32_t main(){
	#ifdef ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);
	#endif
	int t = 1;
	//cin>>t;

	for(int i = 1;i<=t;i++)solve(i);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 11 ms 648 KB Output is correct
5 Correct 13 ms 596 KB Output is correct
6 Correct 13 ms 684 KB Output is correct
7 Correct 13 ms 644 KB Output is correct
8 Correct 13 ms 672 KB Output is correct
9 Correct 14 ms 700 KB Output is correct
10 Correct 13 ms 596 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 24 ms 876 KB Output is correct
13 Correct 24 ms 892 KB Output is correct
14 Correct 24 ms 848 KB Output is correct
15 Correct 24 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 11 ms 648 KB Output is correct
5 Correct 13 ms 596 KB Output is correct
6 Correct 13 ms 684 KB Output is correct
7 Correct 13 ms 644 KB Output is correct
8 Correct 13 ms 672 KB Output is correct
9 Correct 14 ms 700 KB Output is correct
10 Correct 13 ms 596 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 24 ms 876 KB Output is correct
13 Correct 24 ms 892 KB Output is correct
14 Correct 24 ms 848 KB Output is correct
15 Correct 24 ms 896 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 13 ms 596 KB Output is correct
18 Correct 22 ms 848 KB Output is correct
19 Correct 22 ms 848 KB Output is correct
20 Correct 23 ms 848 KB Output is correct
21 Correct 22 ms 848 KB Output is correct
22 Correct 23 ms 868 KB Output is correct
23 Correct 24 ms 892 KB Output is correct
24 Correct 22 ms 848 KB Output is correct
25 Correct 22 ms 884 KB Output is correct
26 Correct 43 ms 1356 KB Output is correct
27 Correct 43 ms 1356 KB Output is correct
28 Correct 45 ms 1356 KB Output is correct
29 Correct 44 ms 1484 KB Output is correct
30 Correct 44 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 7 ms 468 KB Output is correct
5 Correct 33 ms 1016 KB Output is correct
6 Correct 44 ms 1096 KB Output is correct
7 Correct 33 ms 1028 KB Output is correct
8 Correct 33 ms 1096 KB Output is correct
9 Correct 32 ms 1076 KB Output is correct
10 Correct 34 ms 1076 KB Output is correct
11 Correct 33 ms 1092 KB Output is correct
12 Correct 39 ms 1072 KB Output is correct
13 Correct 39 ms 1220 KB Output is correct
14 Correct 35 ms 1092 KB Output is correct
15 Correct 44 ms 1364 KB Output is correct