Submission #396719

# Submission time Handle Problem Language Result Execution time Memory
396719 2021-04-30T16:17:37 Z rainboy Sorting (IOI15_sorting) C
0 / 100
15 ms 364 KB
#include "sorting.h"
#include <string.h>

#define N	200000

int findSwapPairs(int n, int pp[], int m, int aa[], int bb[], int ii[], int jj[]) {
	static char visited[N];
	static int vv[N];
	int h, i, j, r, cnt;

	for (i = 0; i < n; i++)
		vv[pp[i]] = i;
	for (r = 1; r <= m; r++) {
		int p, q, u, v;

		p = pp[aa[r - 1]], q = pp[bb[r - 1]], u = aa[r - 1], v = bb[r - 1];
		pp[v] = p, vv[p] = v, pp[u] = q, vv[q] = u;
		memset(visited, 0, n * sizeof *visited);
		cnt = 0;
		for (i = 0; i < n; i++)
			if (!visited[i]) {
				visited[i] = 1;
				for (j = pp[i]; !visited[j]; j = pp[j])
					visited[j] = 1, ii[cnt] = pp[i], jj[cnt] = pp[j], cnt++;
				while (!visited[i])
					visited[i] = 1, i = pp[i];
			}
		if (cnt <= r) {
			for (h = r - 1; h >= 0; h--) {
				if (h < cnt)
					ii[h] = vv[ii[h]], jj[h] = vv[jj[h]];
				else
					ii[h] = 0, jj[h] = 0;
				p = pp[aa[h]], q = pp[bb[h]], u = aa[h], v = bb[h];
				pp[v] = p, vv[p] = v, pp[u] = q, vv[q] = u;
			}
			return r;
		}
	}
	return 1;
}

Compilation message

sorting.c: In function 'findSwapPairs':
sorting.c:18:24: warning: conversion to 'long unsigned int' from 'int' may change the sign of the result [-Wsign-conversion]
   18 |   memset(visited, 0, n * sizeof *visited);
      |                        ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 356 KB Output is correct
2 Correct 15 ms 364 KB Output is correct
3 Correct 13 ms 332 KB Output is correct
4 Incorrect 2 ms 300 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 356 KB Output is correct
2 Correct 15 ms 364 KB Output is correct
3 Correct 13 ms 332 KB Output is correct
4 Incorrect 2 ms 300 KB Output isn't correct
5 Halted 0 ms 0 KB -