結果

問題 No.527 ナップサック容量問題
ユーザー femtofemto
提出日時 2017-06-09 23:26:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 1,512 ms
コンパイル使用メモリ 167,568 KB
実行使用メモリ 46,608 KB
最終ジャッジ日時 2023-10-24 02:18:51
合計ジャッジ時間 3,445 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
46,604 KB
testcase_01 AC 15 ms
46,604 KB
testcase_02 AC 15 ms
46,604 KB
testcase_03 AC 15 ms
46,604 KB
testcase_04 AC 15 ms
46,604 KB
testcase_05 AC 19 ms
46,608 KB
testcase_06 AC 27 ms
46,608 KB
testcase_07 AC 25 ms
46,608 KB
testcase_08 AC 19 ms
46,604 KB
testcase_09 AC 15 ms
46,604 KB
testcase_10 AC 27 ms
46,608 KB
testcase_11 AC 23 ms
46,608 KB
testcase_12 AC 19 ms
46,608 KB
testcase_13 AC 27 ms
46,608 KB
testcase_14 AC 18 ms
46,604 KB
testcase_15 AC 21 ms
46,608 KB
testcase_16 AC 15 ms
46,604 KB
testcase_17 AC 20 ms
46,608 KB
testcase_18 AC 20 ms
46,608 KB
testcase_19 AC 14 ms
46,604 KB
testcase_20 AC 18 ms
46,604 KB
testcase_21 AC 28 ms
46,608 KB
testcase_22 AC 24 ms
46,608 KB
testcase_23 AC 27 ms
46,608 KB
testcase_24 AC 16 ms
46,604 KB
testcase_25 AC 23 ms
46,608 KB
testcase_26 AC 22 ms
46,608 KB
testcase_27 AC 21 ms
46,608 KB
testcase_28 AC 21 ms
46,608 KB
testcase_29 AC 30 ms
46,608 KB
testcase_30 AC 15 ms
46,604 KB
testcase_31 AC 17 ms
46,604 KB
testcase_32 AC 20 ms
46,604 KB
testcase_33 AC 19 ms
46,604 KB
testcase_34 AC 19 ms
46,608 KB
testcase_35 AC 22 ms
46,608 KB
testcase_36 AC 14 ms
46,604 KB
testcase_37 AC 18 ms
46,604 KB
testcase_38 AC 21 ms
46,604 KB
testcase_39 AC 20 ms
46,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int dp[110][100010];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, V;
	cin >> N;

	const int INF = 1 << 28;
	fill((int*)begin(dp), (int*)end(dp), -INF);
	dp[0][0] = 0;
	for(int i = 0; i < N; i++) {
		int v, w;
		cin >> v >> w;
		for(int j = 0; j <= 100000; j++) {
			if(dp[i][j] == -INF) continue;
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v);
		}
	}
	cin >> V;
	int minW = INF, maxW = 0;
	int v = 0;
	for(int j = 1; j <= 100000; j++) {
		v = max(v, dp[N][j]);
		if(v == V) {
			minW = min(minW, j);
			maxW = max(maxW, j);
		}
	}

	cout << minW << endl;
	if(maxW == 100000) cout << "inf" << endl;
	else cout << maxW << endl;
}
0