답안 #537113

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
537113 2022-03-14T14:36:40 Z rainboy 스트랩 (JOI14_straps) C
100 / 100
21 ms 436 KB
#include <stdio.h>
#include <string.h>

#define N	2000
#define INF	0x7fffffff

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

int main() {
	static int dp[N + N + 1], dq[N + N + 1];
	int n, i, s, t, ans;

	scanf("%d", &n);
	for (s = -n; s <= n; s++)
		dp[n + s] = -INF;
	dp[n + 1] = 0;
	for (i = 0; i < n; i++) {
		int a, b;

		scanf("%d%d", &a, &b), a--;
		memcpy(dq, dp, (n * 2 + 1) * sizeof *dp);
		for (s = -n; s <= n; s++) {
			int x = dq[n + s];

			if (x == -INF)
				continue;
			t = min(s + a, n);
			dp[n + t] = max(dp[n + t], x + b);
		}
	}
	ans = -INF;
	for (s = 0; s <= n; s++)
		ans = max(ans, dp[n + s]);
	printf("%d\n", ans);
	return 0;
}

Compilation message

straps.c: In function 'main':
straps.c:14:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
straps.c:21:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   scanf("%d%d", &a, &b), a--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 292 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 296 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 292 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 296 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 296 KB Output is correct
17 Correct 0 ms 300 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 296 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 300 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 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 5 ms 300 KB Output is correct
9 Correct 3 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 11 ms 436 KB Output is correct
13 Correct 12 ms 308 KB Output is correct
14 Correct 14 ms 212 KB Output is correct
15 Correct 10 ms 340 KB Output is correct
16 Correct 10 ms 336 KB Output is correct
17 Correct 11 ms 332 KB Output is correct
18 Correct 10 ms 340 KB Output is correct
19 Correct 11 ms 332 KB Output is correct
20 Correct 10 ms 308 KB Output is correct
21 Correct 13 ms 336 KB Output is correct
22 Correct 10 ms 336 KB Output is correct
23 Correct 14 ms 332 KB Output is correct
24 Correct 10 ms 212 KB Output is correct
25 Correct 13 ms 212 KB Output is correct
26 Correct 11 ms 332 KB Output is correct
27 Correct 13 ms 328 KB Output is correct
28 Correct 10 ms 304 KB Output is correct
29 Correct 19 ms 304 KB Output is correct
30 Correct 20 ms 212 KB Output is correct
31 Correct 21 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 224 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 288 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 3 ms 320 KB Output is correct
14 Correct 3 ms 304 KB Output is correct
15 Correct 4 ms 212 KB Output is correct
16 Correct 3 ms 304 KB Output is correct
17 Correct 12 ms 340 KB Output is correct
18 Correct 14 ms 332 KB Output is correct
19 Correct 11 ms 340 KB Output is correct
20 Correct 9 ms 212 KB Output is correct
21 Correct 9 ms 340 KB Output is correct
22 Correct 9 ms 308 KB Output is correct
23 Correct 9 ms 332 KB Output is correct
24 Correct 10 ms 340 KB Output is correct
25 Correct 9 ms 336 KB Output is correct
26 Correct 9 ms 212 KB Output is correct
27 Correct 9 ms 340 KB Output is correct
28 Correct 9 ms 340 KB Output is correct
29 Correct 10 ms 332 KB Output is correct
30 Correct 9 ms 308 KB Output is correct
31 Correct 10 ms 332 KB Output is correct
32 Correct 9 ms 340 KB Output is correct
33 Correct 13 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 336 KB Output is correct
2 Correct 12 ms 336 KB Output is correct
3 Correct 11 ms 340 KB Output is correct
4 Correct 10 ms 340 KB Output is correct
5 Correct 12 ms 336 KB Output is correct
6 Correct 12 ms 332 KB Output is correct
7 Correct 12 ms 336 KB Output is correct
8 Correct 13 ms 332 KB Output is correct
9 Correct 12 ms 212 KB Output is correct
10 Correct 12 ms 336 KB Output is correct
11 Correct 12 ms 308 KB Output is correct
12 Correct 17 ms 212 KB Output is correct
13 Correct 13 ms 308 KB Output is correct
14 Correct 17 ms 336 KB Output is correct
15 Correct 13 ms 328 KB Output is correct
16 Correct 12 ms 336 KB Output is correct
17 Correct 13 ms 340 KB Output is correct
18 Correct 15 ms 368 KB Output is correct
19 Correct 14 ms 212 KB Output is correct
20 Correct 15 ms 340 KB Output is correct
21 Correct 14 ms 340 KB Output is correct
22 Correct 16 ms 336 KB Output is correct
23 Correct 15 ms 304 KB Output is correct
24 Correct 15 ms 340 KB Output is correct
25 Correct 11 ms 340 KB Output is correct