This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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, j, l;
scanf("%d%d", &n, &t);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
if (t == 1)
for (i = 0; i < n; i++)
for (j = i; j > 0 && aa[j] < aa[j - 1]; j--)
move(j, j - 1), move(j - 1, j), move(j, j - 1);
else 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 (stderr)
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]);
| ^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |