#include <bits/stdc++.h>
using namespace std;
int n, cc, s, i, k, curr, j, mx;
vector<pair<int, int> > ans;
int a[1005], b[1005];
bool hasBit;
void oper(int x, int y) {
a[x] ^= a[y];
ans.push_back(make_pair(x,y));
}
int main() {
scanf("%d%d", &n, &s);
for (i=1; i <= n; ++i) {
scanf("%d", &a[i]);
b[i] = a[i];
}
if (s == 1) {
for (i=n; i >= 1; --i) {
for (j=1; j <= min(n-1, i); ++j) {
oper(j, j+1);
}
curr = 1;
for (j=2; j <= i; ++j) {
if (b[j]>b[curr]) {
curr = j;
}
}
for (j=curr-2; j >= 1; --j) {
oper(j, j+1);
}
for (j=curr+1; j <= i; ++j) {
oper(j, j-1);
}
mx = b[curr];
for (j=curr; j < i; ++j) {
b[j] = b[j+1];
}
b[i]=mx;
}
}
else {
for (i=19; i >= 0; --i) {
hasBit = false;
for (j=1; j <= n; ++j) {
if ((a[j]>>i)&1) {
hasBit = true;
}
}
if (hasBit) {
for (j=2; j <= n; ++j) {
if (!((a[j]>>i)&1)) {
oper(j, j-1);
}
}
for (j=1; j < n; ++j) {
if ((a[j]>>i)&1) {
oper(j, j+1);
}
}
--n;
}
}
}
printf("%d\n", (int)ans.size());
for (i=0; i < (int)ans.size(); ++i) {
printf("%d %d\n", ans[i].first, ans[i].second);
}
return 0;
}
Compilation message
xorsort.cpp: In function 'int main()':
xorsort.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%d%d", &n, &s);
| ~~~~~^~~~~~~~~~~~~~~~
xorsort.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
6 ms |
712 KB |
Output is correct |
5 |
Correct |
5 ms |
712 KB |
Output is correct |
6 |
Correct |
6 ms |
712 KB |
Output is correct |
7 |
Correct |
6 ms |
712 KB |
Output is correct |
8 |
Correct |
5 ms |
676 KB |
Output is correct |
9 |
Correct |
5 ms |
712 KB |
Output is correct |
10 |
Correct |
6 ms |
684 KB |
Output is correct |
11 |
Correct |
6 ms |
712 KB |
Output is correct |
12 |
Correct |
6 ms |
712 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
6 ms |
712 KB |
Output is correct |
15 |
Correct |
6 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
292 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
6 ms |
712 KB |
Output is correct |
5 |
Correct |
5 ms |
712 KB |
Output is correct |
6 |
Correct |
6 ms |
712 KB |
Output is correct |
7 |
Correct |
6 ms |
712 KB |
Output is correct |
8 |
Correct |
5 ms |
676 KB |
Output is correct |
9 |
Correct |
5 ms |
712 KB |
Output is correct |
10 |
Correct |
6 ms |
684 KB |
Output is correct |
11 |
Correct |
6 ms |
712 KB |
Output is correct |
12 |
Correct |
6 ms |
712 KB |
Output is correct |
13 |
Correct |
6 ms |
716 KB |
Output is correct |
14 |
Correct |
6 ms |
712 KB |
Output is correct |
15 |
Correct |
6 ms |
676 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
5 ms |
712 KB |
Output is correct |
18 |
Correct |
9 ms |
932 KB |
Output is correct |
19 |
Correct |
9 ms |
944 KB |
Output is correct |
20 |
Correct |
9 ms |
936 KB |
Output is correct |
21 |
Correct |
9 ms |
900 KB |
Output is correct |
22 |
Correct |
9 ms |
1092 KB |
Output is correct |
23 |
Correct |
9 ms |
1092 KB |
Output is correct |
24 |
Correct |
10 ms |
964 KB |
Output is correct |
25 |
Correct |
9 ms |
980 KB |
Output is correct |
26 |
Correct |
9 ms |
936 KB |
Output is correct |
27 |
Correct |
9 ms |
976 KB |
Output is correct |
28 |
Correct |
12 ms |
928 KB |
Output is correct |
29 |
Correct |
9 ms |
964 KB |
Output is correct |
30 |
Correct |
9 ms |
964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
8 ms |
840 KB |
Output is correct |
6 |
Correct |
7 ms |
792 KB |
Output is correct |
7 |
Correct |
7 ms |
840 KB |
Output is correct |
8 |
Correct |
7 ms |
824 KB |
Output is correct |
9 |
Correct |
7 ms |
808 KB |
Output is correct |
10 |
Correct |
7 ms |
900 KB |
Output is correct |
11 |
Correct |
8 ms |
840 KB |
Output is correct |
12 |
Correct |
8 ms |
936 KB |
Output is correct |
13 |
Correct |
8 ms |
840 KB |
Output is correct |
14 |
Correct |
8 ms |
944 KB |
Output is correct |
15 |
Correct |
9 ms |
1036 KB |
Output is correct |