結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 4 ms
6,940 KB
testcase_03 AC 3 ms
7,756 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 14 ms
23,372 KB
testcase_06 AC 26 ms
43,688 KB
testcase_07 AC 21 ms
35,584 KB
testcase_08 AC 12 ms
20,432 KB
testcase_09 AC 3 ms
6,948 KB
testcase_10 AC 24 ms
44,368 KB
testcase_11 AC 19 ms
32,000 KB
testcase_12 AC 14 ms
26,092 KB
testcase_13 AC 26 ms
45,164 KB
testcase_14 AC 10 ms
18,304 KB
testcase_15 AC 15 ms
26,880 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 13 ms
22,784 KB
testcase_18 AC 15 ms
25,728 KB
testcase_19 AC 4 ms
6,144 KB
testcase_20 AC 11 ms
19,200 KB
testcase_21 AC 29 ms
50,432 KB
testcase_22 AC 20 ms
35,084 KB
testcase_23 AC 27 ms
49,024 KB
testcase_24 AC 8 ms
12,576 KB
testcase_25 AC 19 ms
34,376 KB
testcase_26 AC 17 ms
32,332 KB
testcase_27 AC 17 ms
31,464 KB
testcase_28 AC 16 ms
28,108 KB
testcase_29 AC 29 ms
50,048 KB
testcase_30 AC 6 ms
8,192 KB
testcase_31 AC 14 ms
23,168 KB
testcase_32 AC 16 ms
27,904 KB
testcase_33 AC 14 ms
24,320 KB
testcase_34 AC 17 ms
28,928 KB
testcase_35 AC 16 ms
28,916 KB
testcase_36 AC 4 ms
5,376 KB
testcase_37 AC 14 ms
22,400 KB
testcase_38 AC 15 ms
27,520 KB
testcase_39 AC 15 ms
26,380 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 = 1; 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