#include <bits/stdc++.h>
using namespace std;
int n, s, i, k, curr, j, mx;
vector<pair<int, int> > ans;
int a[1005], b[1005];
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;
}
}
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:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d%d", &n, &s);
| ~~~~~^~~~~~~~~~~~~~~~
xorsort.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
712 KB |
Output is correct |
5 |
Correct |
6 ms |
708 KB |
Output is correct |
6 |
Correct |
6 ms |
712 KB |
Output is correct |
7 |
Correct |
7 ms |
664 KB |
Output is correct |
8 |
Correct |
6 ms |
712 KB |
Output is correct |
9 |
Correct |
5 ms |
712 KB |
Output is correct |
10 |
Correct |
5 ms |
716 KB |
Output is correct |
11 |
Correct |
5 ms |
712 KB |
Output is correct |
12 |
Correct |
5 ms |
680 KB |
Output is correct |
13 |
Correct |
5 ms |
712 KB |
Output is correct |
14 |
Correct |
6 ms |
712 KB |
Output is correct |
15 |
Correct |
6 ms |
712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
5 ms |
712 KB |
Output is correct |
5 |
Correct |
6 ms |
708 KB |
Output is correct |
6 |
Correct |
6 ms |
712 KB |
Output is correct |
7 |
Correct |
7 ms |
664 KB |
Output is correct |
8 |
Correct |
6 ms |
712 KB |
Output is correct |
9 |
Correct |
5 ms |
712 KB |
Output is correct |
10 |
Correct |
5 ms |
716 KB |
Output is correct |
11 |
Correct |
5 ms |
712 KB |
Output is correct |
12 |
Correct |
5 ms |
680 KB |
Output is correct |
13 |
Correct |
5 ms |
712 KB |
Output is correct |
14 |
Correct |
6 ms |
712 KB |
Output is correct |
15 |
Correct |
6 ms |
712 KB |
Output is correct |
16 |
Correct |
1 ms |
296 KB |
Output is correct |
17 |
Correct |
6 ms |
716 KB |
Output is correct |
18 |
Correct |
12 ms |
964 KB |
Output is correct |
19 |
Correct |
9 ms |
964 KB |
Output is correct |
20 |
Correct |
11 ms |
964 KB |
Output is correct |
21 |
Correct |
12 ms |
952 KB |
Output is correct |
22 |
Correct |
9 ms |
964 KB |
Output is correct |
23 |
Correct |
9 ms |
964 KB |
Output is correct |
24 |
Correct |
9 ms |
960 KB |
Output is correct |
25 |
Correct |
9 ms |
964 KB |
Output is correct |
26 |
Correct |
9 ms |
964 KB |
Output is correct |
27 |
Correct |
9 ms |
964 KB |
Output is correct |
28 |
Correct |
9 ms |
964 KB |
Output is correct |
29 |
Correct |
9 ms |
964 KB |
Output is correct |
30 |
Correct |
9 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Not sorted |
2 |
Halted |
0 ms |
0 KB |
- |