結果

問題 No.527 ナップサック容量問題
ユーザー nksk38nksk38
提出日時 2017-06-20 20:10:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 856 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 73,772 KB
実行使用メモリ 42,368 KB
最終ジャッジ日時 2024-04-10 06:27:25
合計ジャッジ時間 1,988 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 10 ms
18,944 KB
testcase_06 AC 18 ms
36,608 KB
testcase_07 AC 14 ms
30,080 KB
testcase_08 AC 8 ms
16,640 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 19 ms
36,992 KB
testcase_11 AC 12 ms
26,752 KB
testcase_12 AC 9 ms
20,224 KB
testcase_13 AC 18 ms
38,016 KB
testcase_14 AC 7 ms
15,488 KB
testcase_15 AC 11 ms
23,040 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 9 ms
19,456 KB
testcase_18 AC 11 ms
21,760 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 8 ms
16,256 KB
testcase_21 AC 22 ms
42,368 KB
testcase_22 AC 15 ms
29,184 KB
testcase_23 AC 20 ms
41,216 KB
testcase_24 AC 6 ms
10,752 KB
testcase_25 AC 14 ms
28,544 KB
testcase_26 AC 12 ms
25,600 KB
testcase_27 AC 13 ms
26,112 KB
testcase_28 AC 11 ms
22,912 KB
testcase_29 AC 21 ms
42,112 KB
testcase_30 AC 4 ms
7,040 KB
testcase_31 AC 10 ms
19,712 KB
testcase_32 AC 11 ms
23,680 KB
testcase_33 AC 11 ms
20,480 KB
testcase_34 AC 13 ms
24,576 KB
testcase_35 AC 12 ms
24,576 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 10 ms
18,944 KB
testcase_38 AC 11 ms
23,168 KB
testcase_39 AC 11 ms
22,016 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

int N,V;
int v[110], w[110];
int dp[110][100010];

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 = 1; j <= 100000; j++) {
			if (w[i] <= j) {
				dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]]+v[i]);
			}
			else {
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	int mi=1000000,mx = 0;
	for (int i = 1; i <= 100000; i++) {
		if (dp[N][i] == V) {
			if (i < mi)mi = i;
			if (i > mx)mx = i;
		}
	}
	cout << mi << endl;
	if (mx != 100000)
		cout << mx << endl;
	else
		cout << "inf" << endl;
	return 0;
}
0