Submission #550651

# Submission time Handle Problem Language Result Execution time Memory
550651 2022-04-18T18:49:08 Z rainboy JOI15_building3 (JOI15_building3) C
100 / 100
119 ms 11952 KB
#include <stdio.h>

#define N	1000000

int main() {
	static int aa[N];
	static char used[N + 1];
	int n, h, i, j, a;
	long long ans;

	scanf("%d", &n);
	for (i = 0; i < n - 1; i++)
		scanf("%d", &aa[i]);
	used[0] = 1;
	a = 0;
	for (i = 0; i < n - 1; i++) {
		if (!used[aa[i] - 1]) {
			if (a == 0)
				a = aa[i];
			else if (a != aa[i]) {
				printf("0\n");
				return 0;
			}
		}
		used[aa[i]] = 1;
	}
	if (a == 0) {
		ans = 1, a = 0;
		for (i = 0; i < n - 1; i++) {
			if (a + 1 == aa[i])
				a++;
			ans += a;
		}
		printf("%lld\n", ans);
		return 0;
	}
	for (j = 0; j < n - 1; j++)
		if (aa[j] == a)
			break;
	if (a == 2)
		i = -1;
	else
		for (i = 0; i < n - 1; i++)
			if (aa[i] == a - 2)
				break;
	if (i > j) {
		printf("0\n");
		return 0;
	}
	ans = 0;
	for (h = i; h < j; h++)
		if (h < 0 || aa[h] != a - 1)
			ans++;
	printf("%lld\n", ans);
	return 0;
}

Compilation message

building3.c: In function 'main':
building3.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
building3.c:13:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 284 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 304 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 284 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 0 ms 300 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 304 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 83 ms 8100 KB Output is correct
22 Correct 82 ms 8008 KB Output is correct
23 Correct 93 ms 7960 KB Output is correct
24 Correct 108 ms 11860 KB Output is correct
25 Correct 109 ms 11892 KB Output is correct
26 Correct 99 ms 11776 KB Output is correct
27 Correct 113 ms 11856 KB Output is correct
28 Correct 98 ms 11952 KB Output is correct
29 Correct 74 ms 6068 KB Output is correct
30 Correct 80 ms 7728 KB Output is correct
31 Correct 87 ms 8404 KB Output is correct
32 Correct 86 ms 8452 KB Output is correct
33 Correct 86 ms 8468 KB Output is correct
34 Correct 86 ms 8424 KB Output is correct
35 Correct 119 ms 11492 KB Output is correct