Submission #500648

# Submission time Handle Problem Language Result Execution time Memory
500648 2021-12-31T16:32:25 Z rainboy Tortoise (CEOI21_tortoise) C
73 / 100
403 ms 391832 KB
#include <stdio.h>
#include <string.h>

#define N	5000
#define INF	0x3f3f3f3f

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

int eval(int a, int b, int c) {
	return b - a * c;
}

int main() {
	static int aa[N], ll[N], rr[N], tt[N], dp[N][N * 2 + 1], dq[N][N * 2 + 1], dr[N * 2 + 1], qu[N * 2 + 1];
	int n, i, j, k, head, cnt, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (i = 0; i < n; i++) {
		for (j = i - 1; j >= 0; j--)
			if (aa[j] == -1)
				break;
		ll[i] = j;
		for (j = i + 1; j < n; j++)
			if (aa[j] == -1)
				break;
		rr[i] = j;
		tt[i] = min(ll[i] == -1 ? INF : i - ll[i], rr[i] == n ? INF : rr[i] - i) * 2;
	}
	for (i = 0; i < n; i++) {
		memset(dp[i], 0x3f, (n * 2 + 1) * sizeof *dp[i]);
		memset(dq[i], 0x3f, (n * 2 + 1) * sizeof *dq[i]);
	}
	ans = 0;
	for (i = 0; i < n; i++)
		if (aa[i] > 0) {
			for (k = 0; k <= n * 2; k++) {
				if ((j = ll[i]) >= 0)
					dp[i][k] = min(dp[i][k], dq[j][k] + i - j);
				if ((j = rr[i]) < n)
					dp[i][k] = min(dp[i][k], dq[j][k] + j - i);
			}
			dp[i][1] = min(dp[i][1], i);
			head = cnt = 0;
			for (k = 0; k <= n * 2; k++) {
				if (dp[i][k] <= i * 2) {
					while (cnt && eval(qu[head + cnt - 1], dp[i][qu[head + cnt - 1]], tt[i]) >= eval(k, dp[i][k], tt[i]))
						cnt--;
					qu[head + cnt++] = k;
				}
				while (cnt && k - qu[head] >= aa[i])
					head++, cnt--;
				dr[k] = cnt == 0 ? INF : eval(qu[head], dp[i][qu[head]], tt[i]) + tt[i] * k;
			}
			for (k = 0; k <= n * 2; k++)
				dp[i][k] = dr[k];
			for (k = 0; k <= n * 2; k++) {
				int t = dp[i][k];

				if (t > i * 2)
					continue;
				ans = max(ans, k);
				if (k < n * 2) {
					if ((j = ll[i]) >= 0)
						dq[j][k + 1] = min(dq[j][k + 1], t + i - j);
					if ((j = rr[i]) < n)
						dq[j][k + 1] = min(dq[j][k + 1], t + j - i);
				}
			}
		} else
			for (k = 0; k <= n * 2; k++) {
				int t = dq[i][k];

				if (t == INF)
					continue;
				if ((j = rr[i]) < n)
					dq[j][k] = min(dq[j][k], t + j - i);
			}
	ans = -ans;
	for (i = 0; i < n; i++)
		if (aa[i] > 0)
			ans += aa[i];
	printf("%d\n", ans);
	return 0;
}

Compilation message

tortoise.c: In function 'main':
tortoise.c:18:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
tortoise.c:20:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 412 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 408 KB Output is correct
14 Correct 0 ms 408 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 404 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 412 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 412 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 408 KB Output is correct
14 Correct 0 ms 408 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 404 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 412 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 3276 KB Output is correct
28 Correct 2 ms 3916 KB Output is correct
29 Correct 2 ms 3660 KB Output is correct
30 Correct 2 ms 3404 KB Output is correct
31 Correct 2 ms 3996 KB Output is correct
32 Correct 1 ms 2764 KB Output is correct
33 Correct 2 ms 3660 KB Output is correct
34 Correct 3 ms 3404 KB Output is correct
35 Correct 2 ms 4044 KB Output is correct
36 Correct 2 ms 4044 KB Output is correct
37 Correct 2 ms 4044 KB Output is correct
38 Correct 2 ms 4044 KB Output is correct
39 Correct 2 ms 4044 KB Output is correct
40 Correct 2 ms 4044 KB Output is correct
41 Correct 3 ms 4148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 412 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 408 KB Output is correct
14 Correct 0 ms 408 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 404 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 412 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 3276 KB Output is correct
28 Correct 2 ms 3916 KB Output is correct
29 Correct 2 ms 3660 KB Output is correct
30 Correct 2 ms 3404 KB Output is correct
31 Correct 2 ms 3996 KB Output is correct
32 Correct 1 ms 2764 KB Output is correct
33 Correct 2 ms 3660 KB Output is correct
34 Correct 3 ms 3404 KB Output is correct
35 Correct 2 ms 4044 KB Output is correct
36 Correct 2 ms 4044 KB Output is correct
37 Correct 2 ms 4044 KB Output is correct
38 Correct 2 ms 4044 KB Output is correct
39 Correct 2 ms 4044 KB Output is correct
40 Correct 2 ms 4044 KB Output is correct
41 Correct 3 ms 4148 KB Output is correct
42 Correct 1 ms 2508 KB Output is correct
43 Correct 1 ms 2636 KB Output is correct
44 Correct 2 ms 3076 KB Output is correct
45 Correct 2 ms 3788 KB Output is correct
46 Correct 2 ms 2892 KB Output is correct
47 Correct 1 ms 2508 KB Output is correct
48 Correct 2 ms 3404 KB Output is correct
49 Correct 2 ms 2892 KB Output is correct
50 Correct 2 ms 3660 KB Output is correct
51 Correct 2 ms 3788 KB Output is correct
52 Correct 1 ms 2636 KB Output is correct
53 Correct 2 ms 3788 KB Output is correct
54 Correct 3 ms 3788 KB Output is correct
55 Correct 4 ms 3404 KB Output is correct
56 Correct 2 ms 4044 KB Output is correct
57 Correct 2 ms 2636 KB Output is correct
58 Correct 3 ms 3708 KB Output is correct
59 Correct 2 ms 2892 KB Output is correct
60 Correct 3 ms 3404 KB Output is correct
61 Correct 2 ms 3660 KB Output is correct
62 Correct 2 ms 3740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 412 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 408 KB Output is correct
14 Correct 0 ms 408 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 404 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 412 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 3276 KB Output is correct
28 Correct 2 ms 3916 KB Output is correct
29 Correct 2 ms 3660 KB Output is correct
30 Correct 2 ms 3404 KB Output is correct
31 Correct 2 ms 3996 KB Output is correct
32 Correct 1 ms 2764 KB Output is correct
33 Correct 2 ms 3660 KB Output is correct
34 Correct 3 ms 3404 KB Output is correct
35 Correct 2 ms 4044 KB Output is correct
36 Correct 2 ms 4044 KB Output is correct
37 Correct 2 ms 4044 KB Output is correct
38 Correct 2 ms 4044 KB Output is correct
39 Correct 2 ms 4044 KB Output is correct
40 Correct 2 ms 4044 KB Output is correct
41 Correct 3 ms 4148 KB Output is correct
42 Correct 1 ms 2508 KB Output is correct
43 Correct 1 ms 2636 KB Output is correct
44 Correct 2 ms 3076 KB Output is correct
45 Correct 2 ms 3788 KB Output is correct
46 Correct 2 ms 2892 KB Output is correct
47 Correct 1 ms 2508 KB Output is correct
48 Correct 2 ms 3404 KB Output is correct
49 Correct 2 ms 2892 KB Output is correct
50 Correct 2 ms 3660 KB Output is correct
51 Correct 2 ms 3788 KB Output is correct
52 Correct 1 ms 2636 KB Output is correct
53 Correct 2 ms 3788 KB Output is correct
54 Correct 3 ms 3788 KB Output is correct
55 Correct 4 ms 3404 KB Output is correct
56 Correct 2 ms 4044 KB Output is correct
57 Correct 2 ms 2636 KB Output is correct
58 Correct 3 ms 3708 KB Output is correct
59 Correct 2 ms 2892 KB Output is correct
60 Correct 3 ms 3404 KB Output is correct
61 Correct 2 ms 3660 KB Output is correct
62 Correct 2 ms 3740 KB Output is correct
63 Correct 237 ms 386852 KB Output is correct
64 Correct 336 ms 390076 KB Output is correct
65 Correct 249 ms 390468 KB Output is correct
66 Correct 257 ms 386636 KB Output is correct
67 Correct 257 ms 391764 KB Output is correct
68 Correct 268 ms 384628 KB Output is correct
69 Correct 269 ms 390492 KB Output is correct
70 Correct 330 ms 390872 KB Output is correct
71 Correct 377 ms 390972 KB Output is correct
72 Correct 398 ms 385728 KB Output is correct
73 Correct 383 ms 387440 KB Output is correct
74 Correct 403 ms 388284 KB Output is correct
75 Correct 220 ms 391428 KB Output is correct
76 Correct 301 ms 385156 KB Output is correct
77 Correct 373 ms 391072 KB Output is correct
78 Correct 324 ms 391748 KB Output is correct
79 Correct 294 ms 387268 KB Output is correct
80 Correct 279 ms 386488 KB Output is correct
81 Correct 284 ms 387916 KB Output is correct
82 Correct 289 ms 391236 KB Output is correct
83 Correct 311 ms 387220 KB Output is correct
84 Correct 306 ms 387920 KB Output is correct
85 Correct 321 ms 391348 KB Output is correct
86 Correct 342 ms 391832 KB Output is correct
87 Correct 326 ms 387220 KB Output is correct
88 Correct 292 ms 386592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 412 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 412 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 408 KB Output is correct
14 Correct 0 ms 408 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 404 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 0 ms 332 KB Output is correct
21 Correct 1 ms 412 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 2 ms 3276 KB Output is correct
28 Correct 2 ms 3916 KB Output is correct
29 Correct 2 ms 3660 KB Output is correct
30 Correct 2 ms 3404 KB Output is correct
31 Correct 2 ms 3996 KB Output is correct
32 Correct 1 ms 2764 KB Output is correct
33 Correct 2 ms 3660 KB Output is correct
34 Correct 3 ms 3404 KB Output is correct
35 Correct 2 ms 4044 KB Output is correct
36 Correct 2 ms 4044 KB Output is correct
37 Correct 2 ms 4044 KB Output is correct
38 Correct 2 ms 4044 KB Output is correct
39 Correct 2 ms 4044 KB Output is correct
40 Correct 2 ms 4044 KB Output is correct
41 Correct 3 ms 4148 KB Output is correct
42 Correct 1 ms 2508 KB Output is correct
43 Correct 1 ms 2636 KB Output is correct
44 Correct 2 ms 3076 KB Output is correct
45 Correct 2 ms 3788 KB Output is correct
46 Correct 2 ms 2892 KB Output is correct
47 Correct 1 ms 2508 KB Output is correct
48 Correct 2 ms 3404 KB Output is correct
49 Correct 2 ms 2892 KB Output is correct
50 Correct 2 ms 3660 KB Output is correct
51 Correct 2 ms 3788 KB Output is correct
52 Correct 1 ms 2636 KB Output is correct
53 Correct 2 ms 3788 KB Output is correct
54 Correct 3 ms 3788 KB Output is correct
55 Correct 4 ms 3404 KB Output is correct
56 Correct 2 ms 4044 KB Output is correct
57 Correct 2 ms 2636 KB Output is correct
58 Correct 3 ms 3708 KB Output is correct
59 Correct 2 ms 2892 KB Output is correct
60 Correct 3 ms 3404 KB Output is correct
61 Correct 2 ms 3660 KB Output is correct
62 Correct 2 ms 3740 KB Output is correct
63 Correct 237 ms 386852 KB Output is correct
64 Correct 336 ms 390076 KB Output is correct
65 Correct 249 ms 390468 KB Output is correct
66 Correct 257 ms 386636 KB Output is correct
67 Correct 257 ms 391764 KB Output is correct
68 Correct 268 ms 384628 KB Output is correct
69 Correct 269 ms 390492 KB Output is correct
70 Correct 330 ms 390872 KB Output is correct
71 Correct 377 ms 390972 KB Output is correct
72 Correct 398 ms 385728 KB Output is correct
73 Correct 383 ms 387440 KB Output is correct
74 Correct 403 ms 388284 KB Output is correct
75 Correct 220 ms 391428 KB Output is correct
76 Correct 301 ms 385156 KB Output is correct
77 Correct 373 ms 391072 KB Output is correct
78 Correct 324 ms 391748 KB Output is correct
79 Correct 294 ms 387268 KB Output is correct
80 Correct 279 ms 386488 KB Output is correct
81 Correct 284 ms 387916 KB Output is correct
82 Correct 289 ms 391236 KB Output is correct
83 Correct 311 ms 387220 KB Output is correct
84 Correct 306 ms 387920 KB Output is correct
85 Correct 321 ms 391348 KB Output is correct
86 Correct 342 ms 391832 KB Output is correct
87 Correct 326 ms 387220 KB Output is correct
88 Correct 292 ms 386592 KB Output is correct
89 Runtime error 7 ms 460 KB Execution killed with signal 11
90 Halted 0 ms 0 KB -