結果

問題 No.527 ナップサック容量問題
ユーザー amtgjwamtgjw
提出日時 2018-05-16 12:57:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 67,552 KB
実行使用メモリ 44,008 KB
最終ジャッジ日時 2023-09-10 22:18:40
合計ジャッジ時間 2,313 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,532 KB
testcase_01 AC 3 ms
5,052 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
5,224 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 17 ms
31,644 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 21 ms
37,856 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 10 ms
17,284 KB
testcase_15 AC 13 ms
23,748 KB
testcase_16 AC 3 ms
4,936 KB
testcase_17 AC 12 ms
21,408 KB
testcase_18 AC 12 ms
23,512 KB
testcase_19 AC 4 ms
7,068 KB
testcase_20 AC 9 ms
17,364 KB
testcase_21 AC 24 ms
43,924 KB
testcase_22 AC 16 ms
29,892 KB
testcase_23 AC 23 ms
41,872 KB
testcase_24 AC 6 ms
11,280 KB
testcase_25 AC 16 ms
29,632 KB
testcase_26 AC 15 ms
27,548 KB
testcase_27 AC 14 ms
27,560 KB
testcase_28 AC 13 ms
23,464 KB
testcase_29 AC 23 ms
44,008 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 12 ms
21,560 KB
testcase_32 AC 13 ms
25,500 KB
testcase_33 AC 12 ms
21,436 KB
testcase_34 AC 14 ms
25,492 KB
testcase_35 AC 14 ms
25,496 KB
testcase_36 AC 3 ms
4,532 KB
testcase_37 AC 11 ms
19,332 KB
testcase_38 AC 13 ms
23,484 KB
testcase_39 AC 13 ms
23,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>

using namespace std;

#define REP(i,n)	for(int i=0;i<(n);++i)
#define REPS(i,s,t)	for(int i=(s);i<(t);++i)

#define INF 		2000000007
#define MOD			1000007

#define MAX 		105

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int ll;

int DP[MAX][100005];

int main(){
	int N;cin>>N;

	vector<int> V(N);
	vector<int> W(N);
	REP(i,N){cin>>V[i]>>W[i];}
	int maxV;cin>>maxV;

	int suml = accumulate(V.begin(),V.end(),0);
	if(maxV >= suml){
		int sumW = accumulate(W.begin(),W.end(),0);
		cout << sumW << endl;
		cout << 'i'<<"n" << "f" << endl;
		return 0;
	}

	REPS(i,1,N+1){
		REPS(j,1,100001){
			if(j-W[i-1]<0){
				DP[i][j]=DP[i-1][j];
				continue;
			}
			DP[i][j] = max(DP[i-1][j],DP[i-1][j-W[i-1]]+V[i-1]);
		}
	}

	int k=1;
	while(DP[N][k++]!=maxV);
	cout << (--k) << endl;
	while(DP[N][++k]==maxV);
	cout << (k-1) << endl;
	
	return 0;
}
0