Submission #441888

# Submission time Handle Problem Language Result Execution time Memory
441888 2021-07-06T13:41:56 Z rainboy Teleporters (IOI08_teleporters) C
80 / 100
692 ms 37444 KB
#include <stdio.h>
#include <string.h>

#define N	1000000
#define X	2000000

int main() {
	static int xx[N * 2], ii[N * 2], pp[N * 2], cc[N * 2], kk[X + 1];
	static char visited[N * 2];
	int n, n_, m, h, i, c, x, ans;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n * 2; i++) {
		scanf("%d", &xx[i]);
		kk[xx[i]]++;
	}
	for (x = 1; x <= X; x++)
		kk[x] += kk[x - 1];
	for (i = 0; i < n * 2; i++)
		ii[kk[xx[i] - 1]++] = i;
	for (h = 0; h < n * 2; h++)
		pp[ii[h]] = h + 1 == n * 2 ? -1 : ii[h + 1] ^ 1;
	ans = 0;
	for (i = ii[0] ^ 1; i != -1; i = pp[i])
		visited[i] = 1, ans++;
	memset(kk, 0, (n * 2 + 1) * sizeof *kk);
	for (i = 0; i < n * 2; i++)
		if (!visited[i]) {
			c = 0;
			while (!visited[i]) {
				visited[i] = 1, c++;
				i = pp[i];
			}
			kk[c]++;
			while (visited[i] == 1) {
				visited[i] = 2;
				i = pp[i];
			}
		}
	n_ = 0;
	for (c = n; c >= 1; c--)
		while (kk[c]--)
			cc[n_++] = c;
	for (i = 0; i < n_ && i < m; i++)
		ans += cc[i];
	ans += m * 2 - (m > n_ ? (m - n_) % 2 : 0);
	printf("%d\n", ans);
	return 0;
}

Compilation message

teleporters.c: In function 'main':
teleporters.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
teleporters.c:14:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%d", &xx[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8140 KB Output is correct
2 Correct 15 ms 8396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 8164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 8396 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 11440 KB Output is correct
2 Correct 188 ms 16220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 13924 KB Output is correct
2 Correct 275 ms 20096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 366 ms 25640 KB Output is correct
2 Correct 446 ms 29180 KB Output is correct
3 Correct 493 ms 32196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 607 ms 31940 KB Output is correct
2 Correct 654 ms 34276 KB Output is correct
3 Correct 538 ms 33320 KB Output is correct
4 Incorrect 692 ms 33476 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 665 ms 35960 KB Output is correct
2 Correct 682 ms 36292 KB Output is correct
3 Correct 349 ms 37444 KB Output is correct
4 Correct 624 ms 37332 KB Output is correct