#include <stdio.h>
#define N 1000
#define L 20
#define M 40000
int aa[N], ii[M], jj[M], m;
void move(int i, int j) {
ii[m] = i, jj[m] = j, m++;
aa[i] ^= aa[j];
}
int main() {
int n, t, h, i, l;
scanf("%d%d", &n, &t);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
if (t == 2) {
for (l = L - 1; l >= 0; l--) {
for (i = 0; i + 1 < n; i++)
if ((aa[i] & 1 << l) != 0) {
if ((aa[i + 1] & 1 << l) == 0)
move(i + 1, i);
move(i, i + 1);
}
if ((aa[n - 1] & 1 << l) != 0)
n--;
}
printf("%d\n", m);
for (h = 0; h < m; h++)
printf("%d %d\n", ii[h] + 1, jj[h] + 1);
}
return 0;
}
Compilation message
xorsort.c: In function 'main':
xorsort.c:17:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d%d", &n, &t);
| ^~~~~~~~~~~~~~~~~~~~~
xorsort.c:19:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
284 KB |
Output is correct |
5 |
Correct |
4 ms |
724 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
724 KB |
Output is correct |
8 |
Correct |
4 ms |
724 KB |
Output is correct |
9 |
Correct |
4 ms |
676 KB |
Output is correct |
10 |
Correct |
4 ms |
676 KB |
Output is correct |
11 |
Correct |
4 ms |
724 KB |
Output is correct |
12 |
Correct |
4 ms |
724 KB |
Output is correct |
13 |
Correct |
4 ms |
676 KB |
Output is correct |
14 |
Correct |
4 ms |
672 KB |
Output is correct |
15 |
Correct |
5 ms |
800 KB |
Output is correct |