Submission #920643

# Submission time Handle Problem Language Result Execution time Memory
920643 2024-02-02T20:06:56 Z rainboy None (KOI17_cook) C++17
100 / 100
277 ms 156572 KB
/* https://oj.uz/submission/366848 (leinad2) */
/* used solution to find bugs */
#include <stdio.h>

#define N	3000
#define K	3000
#define INF	0x3f3f3f3f

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

int main() {
	static int ss[K][N + 1], pp[K], dp[K][N], dq[K][N], qu[K][N], head[K], cnt[K];
	int n, k, l, r, t, h, h1, h2, h3, h_, i, ans;

	scanf("%d%d%d%d%d", &k, &n, &l, &r, &t);
	for (h = 0; h < k; h++)
		for (i = 1; i <= n; i++)
			scanf("%d", &ss[h][i]), ss[h][i] += ss[h][i - 1];
	for (h = 0; h < k; h++)
		scanf("%d", &pp[h]), pp[h]--;
	ans = INF;
	for (i = 0; i < n; i++) {
		h1 = h2 = h3 = -1;
		for (h = 0; h < k; h++) {
			if (i >= l && dq[h][i - l] != INF) {
				while (cnt[h] && dq[h][qu[h][head[h] + cnt[h] - 1]] >= dq[h][i - l])
					cnt[h]--;
				qu[h][head[h] + cnt[h]++] = i - l;
			}
			if (cnt[h] && qu[h][head[h]] == i - r - 1)
				head[h]++, cnt[h]--;
			dp[h][i] = i == 0 ? -t : (cnt[h] ? dq[h][qu[h][head[h]]] : INF);
			if (dp[h][i] != INF) {
				dp[h][i] += ss[h][i];
				if (h1 == -1 || dp[h1][i] > dp[h][i])
					h3 = h2, h2 = h1, h1 = h;
				else if (h2 == -1 || dp[h2][i] > dp[h][i])
					h3 = h2, h2 = h;
				else if (h3 == -1 || dp[h3][i] > dp[h][i])
					h3 = h;
			}
		}
		for (h = 0; h < k; h++) {
			if (h1 != h && h1 != pp[h])
				h_ = h1;
			else if (h2 != h && h2 != pp[h])
				h_ = h2;
			else
				h_ = h3;
			dq[h][i] = h_ == -1 ? INF : dp[h_][i] - ss[h][i] + t;
			if (n - i <= r && dq[h][i] != INF)
				ans = min(ans, dq[h][i] + ss[h][n]);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Compilation message

cook.cpp: In function 'int main()':
cook.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d%d%d%d%d", &k, &n, &l, &r, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cook.cpp:18:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |    scanf("%d", &ss[h][i]), ss[h][i] += ss[h][i - 1];
      |    ~~~~~^~~~~~~~~~~~~~~~~
cook.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   scanf("%d", &pp[h]), pp[h]--;
      |   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 11096 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10676 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 11096 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10676 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 11 ms 23644 KB Output is correct
12 Correct 10 ms 23540 KB Output is correct
13 Correct 11 ms 23840 KB Output is correct
14 Correct 9 ms 23640 KB Output is correct
15 Correct 10 ms 23644 KB Output is correct
16 Correct 10 ms 23644 KB Output is correct
17 Correct 11 ms 23872 KB Output is correct
18 Correct 7 ms 17416 KB Output is correct
19 Correct 10 ms 23644 KB Output is correct
20 Correct 7 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 11096 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10676 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 11 ms 23644 KB Output is correct
11 Correct 10 ms 23540 KB Output is correct
12 Correct 11 ms 23840 KB Output is correct
13 Correct 9 ms 23640 KB Output is correct
14 Correct 10 ms 23644 KB Output is correct
15 Correct 10 ms 23644 KB Output is correct
16 Correct 11 ms 23872 KB Output is correct
17 Correct 7 ms 17416 KB Output is correct
18 Correct 10 ms 23644 KB Output is correct
19 Correct 7 ms 14940 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 93 ms 145236 KB Output is correct
22 Correct 97 ms 145236 KB Output is correct
23 Correct 96 ms 145488 KB Output is correct
24 Correct 87 ms 145336 KB Output is correct
25 Correct 84 ms 145232 KB Output is correct
26 Correct 98 ms 145232 KB Output is correct
27 Correct 98 ms 145236 KB Output is correct
28 Correct 82 ms 145324 KB Output is correct
29 Correct 95 ms 145232 KB Output is correct
30 Correct 80 ms 111956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 11096 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10676 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 11 ms 23644 KB Output is correct
11 Correct 10 ms 23540 KB Output is correct
12 Correct 11 ms 23840 KB Output is correct
13 Correct 9 ms 23640 KB Output is correct
14 Correct 10 ms 23644 KB Output is correct
15 Correct 10 ms 23644 KB Output is correct
16 Correct 11 ms 23872 KB Output is correct
17 Correct 7 ms 17416 KB Output is correct
18 Correct 10 ms 23644 KB Output is correct
19 Correct 7 ms 14940 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 85 ms 28240 KB Output is correct
22 Correct 77 ms 28244 KB Output is correct
23 Correct 83 ms 28240 KB Output is correct
24 Correct 65 ms 23636 KB Output is correct
25 Correct 84 ms 28312 KB Output is correct
26 Correct 68 ms 28244 KB Output is correct
27 Correct 82 ms 28240 KB Output is correct
28 Correct 81 ms 28244 KB Output is correct
29 Correct 80 ms 28184 KB Output is correct
30 Correct 73 ms 28184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
3 Correct 2 ms 10844 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 2 ms 11096 KB Output is correct
6 Correct 2 ms 10844 KB Output is correct
7 Correct 2 ms 10676 KB Output is correct
8 Correct 2 ms 10844 KB Output is correct
9 Correct 2 ms 10840 KB Output is correct
10 Correct 11 ms 23644 KB Output is correct
11 Correct 10 ms 23540 KB Output is correct
12 Correct 11 ms 23840 KB Output is correct
13 Correct 9 ms 23640 KB Output is correct
14 Correct 10 ms 23644 KB Output is correct
15 Correct 10 ms 23644 KB Output is correct
16 Correct 11 ms 23872 KB Output is correct
17 Correct 7 ms 17416 KB Output is correct
18 Correct 10 ms 23644 KB Output is correct
19 Correct 7 ms 14940 KB Output is correct
20 Correct 93 ms 145236 KB Output is correct
21 Correct 97 ms 145236 KB Output is correct
22 Correct 96 ms 145488 KB Output is correct
23 Correct 87 ms 145336 KB Output is correct
24 Correct 84 ms 145232 KB Output is correct
25 Correct 98 ms 145232 KB Output is correct
26 Correct 98 ms 145236 KB Output is correct
27 Correct 82 ms 145324 KB Output is correct
28 Correct 95 ms 145232 KB Output is correct
29 Correct 80 ms 111956 KB Output is correct
30 Correct 85 ms 28240 KB Output is correct
31 Correct 77 ms 28244 KB Output is correct
32 Correct 83 ms 28240 KB Output is correct
33 Correct 65 ms 23636 KB Output is correct
34 Correct 84 ms 28312 KB Output is correct
35 Correct 68 ms 28244 KB Output is correct
36 Correct 82 ms 28240 KB Output is correct
37 Correct 81 ms 28244 KB Output is correct
38 Correct 80 ms 28184 KB Output is correct
39 Correct 73 ms 28184 KB Output is correct
40 Correct 2 ms 8540 KB Output is correct
41 Correct 112 ms 33872 KB Output is correct
42 Correct 271 ms 72340 KB Output is correct
43 Correct 272 ms 72464 KB Output is correct
44 Correct 277 ms 156572 KB Output is correct
45 Correct 111 ms 39584 KB Output is correct
46 Correct 141 ms 47444 KB Output is correct
47 Correct 155 ms 51028 KB Output is correct
48 Correct 194 ms 53940 KB Output is correct
49 Correct 272 ms 72480 KB Output is correct
50 Correct 276 ms 72484 KB Output is correct