結果

問題 No.527 ナップサック容量問題
ユーザー ldsybldsyb
提出日時 2017-06-09 23:15:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 614 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 65,104 KB
実行使用メモリ 43,096 KB
最終ジャッジ日時 2023-10-24 01:25:49
合計ジャッジ時間 2,146 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,204 KB
testcase_01 AC 4 ms
5,596 KB
testcase_02 AC 3 ms
4,816 KB
testcase_03 AC 4 ms
5,596 KB
testcase_04 AC 2 ms
4,424 KB
testcase_05 AC 14 ms
19,660 KB
testcase_06 AC 26 ms
37,240 KB
testcase_07 AC 19 ms
30,596 KB
testcase_08 AC 12 ms
17,316 KB
testcase_09 AC 2 ms
4,428 KB
testcase_10 AC 25 ms
37,628 KB
testcase_11 AC 18 ms
27,476 KB
testcase_12 AC 14 ms
20,832 KB
testcase_13 AC 26 ms
38,412 KB
testcase_14 AC 10 ms
16,140 KB
testcase_15 AC 16 ms
23,564 KB
testcase_16 AC 4 ms
5,596 KB
testcase_17 AC 13 ms
20,048 KB
testcase_18 AC 14 ms
22,392 KB
testcase_19 AC 4 ms
5,984 KB
testcase_20 AC 11 ms
16,924 KB
testcase_21 AC 27 ms
43,096 KB
testcase_22 AC 19 ms
29,812 KB
testcase_23 AC 27 ms
41,924 KB
testcase_24 AC 9 ms
11,452 KB
testcase_25 AC 19 ms
29,032 KB
testcase_26 AC 16 ms
26,300 KB
testcase_27 AC 17 ms
26,688 KB
testcase_28 AC 15 ms
23,564 KB
testcase_29 AC 26 ms
42,704 KB
testcase_30 AC 6 ms
7,552 KB
testcase_31 AC 13 ms
20,440 KB
testcase_32 AC 15 ms
24,344 KB
testcase_33 AC 13 ms
21,220 KB
testcase_34 AC 16 ms
25,128 KB
testcase_35 AC 16 ms
25,128 KB
testcase_36 AC 4 ms
5,204 KB
testcase_37 AC 12 ms
19,656 KB
testcase_38 AC 16 ms
23,956 KB
testcase_39 AC 14 ms
22,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int main(){
	int n, V;
	cin >> n;
	int v[n], w[n];
	for(int i = 0; i < n; i++) cin >> v[i] >> w[i];
	cin >> V;
	int dp[n + 1][100001]{};
	for(int i = 0; i < n; i++) for(int j = 0; j < 100001; j++){
		dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		if(j + w[i] < 100001){
			dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
		}
	}
	int l = -1, r = -1;
	for(int i = 1; i < 100001; i++) if(dp[n][i] == V){
		((l == -1) ? l : r) = i;
	}
	if(r == -1) r = l;
	if(r == 100000){
		cout << l << endl << "inf" << endl;
		return 0;
	}
	cout << l << endl << r << endl;
}
0