답안 #882147

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882147 2023-12-02T17:01:45 Z rainboy Fun Palace (CCO18_fun) C
25 / 25
27 ms 584 KB
#include <stdio.h>
#include <string.h>

#define C	20000

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

int main() {
	static int dp[C + 1], dq[C + 1];
	int n, a, b, c, c_, x, ans;

	scanf("%d%d", &n, &b);
	memset(dp, -1, (C + 1) * sizeof *dp);
	for (c = 0; c < b; c++) 
		dp[c] = c;
	while (--n) {
		scanf("%d%d", &a, &b);
		memset(dq, -1, (C + 1) * sizeof *dq);
		x = -1;
		for (c = 0; c < a; c++)
			if (dp[c] != -1) {
				x = max(x, dp[c]);
				dq[c + b] = max(dq[c + b], dp[c] + b);
			}
		if (x != -1)
			for (c = 0; c < b; c++)
				dq[c] = max(dq[c], x + c);
		for (c = a; c <= C; c++) {
			c_ = c >= a + b ? c : c - a;
			dq[c_] = max(dq[c_], dp[c]);
		}
		memcpy(dp, dq, (C + 1) * sizeof *dq);
	}
	ans = 0;
	for (c = 0; c <= C; c++) 
		ans = max(ans, dp[c]);
	printf("%d\n", ans);
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d%d", &n, &b);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:17:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d%d", &a, &b);
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 424 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 24 ms 564 KB Output is correct
8 Correct 23 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 5 ms 348 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 424 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 24 ms 564 KB Output is correct
17 Correct 23 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 5 ms 348 KB Output is correct
23 Correct 5 ms 348 KB Output is correct
24 Correct 23 ms 348 KB Output is correct
25 Correct 23 ms 572 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 27 ms 584 KB Output is correct
28 Correct 27 ms 584 KB Output is correct
29 Correct 26 ms 580 KB Output is correct
30 Correct 19 ms 580 KB Output is correct