結果

問題 No.527 ナップサック容量問題
ユーザー square1001square1001
提出日時 2017-08-22 18:18:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 553 bytes
コンパイル時間 1,652 ms
コンパイル使用メモリ 166,660 KB
実行使用メモリ 50,768 KB
最終ジャッジ日時 2024-04-23 04:46:32
合計ジャッジ時間 3,307 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,816 KB
testcase_01 WA -
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 WA -
testcase_05 AC 14 ms
22,792 KB
testcase_06 AC 27 ms
43,732 KB
testcase_07 AC 20 ms
35,456 KB
testcase_08 AC 12 ms
20,300 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 29 ms
44,040 KB
testcase_11 AC 19 ms
32,128 KB
testcase_12 AC 14 ms
24,192 KB
testcase_13 AC 26 ms
45,180 KB
testcase_14 AC 11 ms
18,644 KB
testcase_15 AC 16 ms
28,760 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 13 ms
23,272 KB
testcase_18 AC 15 ms
26,320 KB
testcase_19 AC 4 ms
6,940 KB
testcase_20 AC 12 ms
19,224 KB
testcase_21 AC 28 ms
50,768 KB
testcase_22 AC 20 ms
34,560 KB
testcase_23 AC 28 ms
49,104 KB
testcase_24 AC 7 ms
12,416 KB
testcase_25 WA -
testcase_26 AC 17 ms
30,660 KB
testcase_27 AC 18 ms
31,720 KB
testcase_28 WA -
testcase_29 AC 29 ms
50,072 KB
testcase_30 AC 7 ms
8,064 KB
testcase_31 AC 14 ms
23,424 KB
testcase_32 AC 17 ms
28,160 KB
testcase_33 AC 14 ms
24,064 KB
testcase_34 AC 17 ms
29,056 KB
testcase_35 AC 16 ms
28,800 KB
testcase_36 WA -
testcase_37 AC 13 ms
22,400 KB
testcase_38 AC 16 ms
27,520 KB
testcase_39 AC 16 ms
25,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int N, V, v[109], w[109], dp[109][120009];
int main() {
	cin >> N;
	for(int i = 0; i < N; i++) cin >> v[i] >> w[i];
	cin >> V;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j <= 120000; j++) {
			dp[i + 1][j] = dp[i][j];
			if(j >= w[i]) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
		}
	}
	vector<int> ret;
	for(int i = 0; i <= 120000; i++) {
		if(dp[N][i] == V) ret.push_back(i);
	}
	cout << ret.front() << endl << (ret.back() == 120000 ? "inf" : to_string(ret.back())) << endl;
	return 0;
}
0