結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,736 KB
testcase_01 AC 3 ms
4,936 KB
testcase_02 WA -
testcase_03 AC 3 ms
4,920 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 21 ms
31,832 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 26 ms
37,780 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 11 ms
17,300 KB
testcase_15 AC 16 ms
23,640 KB
testcase_16 AC 3 ms
4,936 KB
testcase_17 AC 14 ms
21,392 KB
testcase_18 AC 16 ms
23,508 KB
testcase_19 AC 4 ms
7,108 KB
testcase_20 AC 11 ms
17,336 KB
testcase_21 AC 29 ms
43,996 KB
testcase_22 AC 20 ms
29,628 KB
testcase_23 AC 29 ms
41,924 KB
testcase_24 AC 7 ms
11,152 KB
testcase_25 AC 20 ms
29,660 KB
testcase_26 AC 18 ms
27,580 KB
testcase_27 AC 19 ms
27,836 KB
testcase_28 AC 16 ms
23,432 KB
testcase_29 AC 30 ms
43,980 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 17 ms
25,616 KB
testcase_33 AC 14 ms
21,388 KB
testcase_34 WA -
testcase_35 AC 17 ms
25,532 KB
testcase_36 AC 3 ms
4,604 KB
testcase_37 AC 13 ms
19,404 KB
testcase_38 AC 17 ms
23,468 KB
testcase_39 AC 15 ms
23,572 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 << "inf\n";
		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-1) << endl;
	while(DP[N][++k]==maxV);
	cout << (k-1) << endl;
	
	return 0;
}
0