답안 #917335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
917335 2024-01-27T21:26:44 Z rainboy 서울에서 경산까지 (KOI17_travel) C
29 / 100
10 ms 1116 KB
#include <stdio.h>
#include <string.h>

#define W	100000

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

int main() {
	static int dp[W + 1];
	int n, w, s, x;

	scanf("%d%d", &n, &w);
	memset(dp, -1, (w + 1) * sizeof *dp), dp[0] = 0;
	while (n--) {
		int w1, v1, w2, v2;

		scanf("%d%d%d%d", &w1, &v1, &w2, &v2);
		for (s = w; s >= 0; s--) {
			x = dp[s];
			if (x == -1)
				continue;
			dp[s] = -1;
			dp[s + w1] = max(dp[s + w1], x + v1), dp[s + w2] = max(dp[s + w2], x + v2);
		}
	}
	x = 0;
	for (s = 0; s <= w; s++)
		x = max(x, dp[s]);
	printf("%d\n", x);
	return 0;
}

Compilation message

travel.c: In function 'main':
travel.c:12:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf("%d%d", &n, &w);
      |  ^~~~~~~~~~~~~~~~~~~~~
travel.c:17:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d%d%d%d", &w1, &v1, &w2, &v2);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
8 Correct 1 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
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
8 Correct 1 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 4 ms 604 KB Output is correct
13 Correct 5 ms 604 KB Output is correct
14 Runtime error 10 ms 1116 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -