Submission #785000

#TimeUsernameProblemLanguageResultExecution timeMemory
785000rainboyXor Sort (eJOI20_xorsort)C11
65 / 100
5 ms852 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...