Submission #481407

# Submission time Handle Problem Language Result Execution time Memory
481407 2021-10-20T17:26:54 Z rainboy Holding (COCI20_holding) C
110 / 110
49 ms 4172 KB
#include <stdio.h>
#include <string.h>

#define N	100
#define K	10000
#define INF	0x3f3f3f3f

int abs_(int a) { return a > 0 ? a : -a; }
int min(int a, int b) { return a < b ? a : b; }

int main() {
	static int aa[N], dp[N + 1][K + 1];
	int n, l, r, k, i, c, s, ans;

	scanf("%d%d%d%d", &n, &l, &r, &k), l--, r--;
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	for (c = 0; c <= n; c++)
		memset(dp[c], 0x3f, (k + 1) * sizeof *dp[c]);
	dp[0][0] = 0;
	for (i = 0; i < n; i++) {
		for (c = r - l; c >= 0; c--) {
			int d = abs_(i - (l + c));

			for (s = 0; s + d <= k; s++)
				dp[c + 1][s + d] = min(dp[c + 1][s + d], dp[c][s] + aa[i]);
		}
	}
	c = r - l + 1;
	ans = INF;
	for (s = 0; s <= k; s++)
		ans = min(ans, dp[c][s]);
	printf("%d\n", ans);
	return 0;
}

Compilation message

holding.c: In function 'main':
holding.c:15:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d%d%d%d", &n, &l, &r, &k), l--, r--;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
holding.c:17:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 412 KB Output is correct
13 Correct 14 ms 2288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 412 KB Output is correct
13 Correct 14 ms 2288 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 0 ms 416 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 460 KB Output is correct
19 Correct 13 ms 2280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 292 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 412 KB Output is correct
13 Correct 14 ms 2288 KB Output is correct
14 Correct 0 ms 460 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 0 ms 416 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 460 KB Output is correct
19 Correct 13 ms 2280 KB Output is correct
20 Correct 1 ms 844 KB Output is correct
21 Correct 1 ms 844 KB Output is correct
22 Correct 1 ms 716 KB Output is correct
23 Correct 2 ms 2124 KB Output is correct
24 Correct 2 ms 716 KB Output is correct
25 Correct 49 ms 4172 KB Output is correct