結果

問題 No.527 ナップサック容量問題
ユーザー gigimegigime
提出日時 2017-06-10 14:46:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 931 bytes
コンパイル時間 1,395 ms
コンパイル使用メモリ 168,868 KB
実行使用メモリ 82,772 KB
最終ジャッジ日時 2023-10-24 20:28:04
合計ジャッジ時間 3,722 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,632 KB
testcase_01 AC 5 ms
8,632 KB
testcase_02 AC 4 ms
6,584 KB
testcase_03 AC 4 ms
8,632 KB
testcase_04 AC 4 ms
6,584 KB
testcase_05 AC 22 ms
37,308 KB
testcase_06 AC 47 ms
71,072 KB
testcase_07 AC 37 ms
57,788 KB
testcase_08 AC 19 ms
31,228 KB
testcase_09 AC 3 ms
6,584 KB
testcase_10 AC 45 ms
71,856 KB
testcase_11 AC 31 ms
51,544 KB
testcase_12 AC 22 ms
38,260 KB
testcase_13 AC 45 ms
73,416 KB
testcase_14 AC 18 ms
29,112 KB
testcase_15 AC 26 ms
45,500 KB
testcase_16 AC 4 ms
8,632 KB
testcase_17 AC 22 ms
37,308 KB
testcase_18 AC 25 ms
41,404 KB
testcase_19 AC 5 ms
8,632 KB
testcase_20 AC 19 ms
31,160 KB
testcase_21 AC 54 ms
82,772 KB
testcase_22 AC 36 ms
57,788 KB
testcase_23 AC 52 ms
82,364 KB
testcase_24 AC 12 ms
20,920 KB
testcase_25 AC 34 ms
55,740 KB
testcase_26 AC 31 ms
49,596 KB
testcase_27 AC 33 ms
51,644 KB
testcase_28 AC 27 ms
45,500 KB
testcase_29 AC 52 ms
82,364 KB
testcase_30 AC 8 ms
12,728 KB
testcase_31 AC 22 ms
39,356 KB
testcase_32 AC 26 ms
45,500 KB
testcase_33 AC 22 ms
39,356 KB
testcase_34 AC 26 ms
47,548 KB
testcase_35 AC 29 ms
47,548 KB
testcase_36 AC 4 ms
8,632 KB
testcase_37 AC 22 ms
37,308 KB
testcase_38 AC 25 ms
45,500 KB
testcase_39 AC 25 ms
41,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,K;
int dp [101] [200001];
const int INF = 1e9;

int main()
{
	scanf("%d",&N);
	vector<int> V(N),W(N);
	FOR(i,0,N){
		scanf("%d%d",&V [i],&W [i]);
	}
	scanf("%d",&K);

	fill(dp [0],dp [N + 1],-INF);
	dp [0] [0] = 0;
	FOR(i,0,N) FOR(j,0,200001) if(dp [i] [j] >= 0){
		chmax(dp [i + 1] [j],dp [i] [j]);
		chmax(dp [i + 1] [j + W [i]],dp [i] [j] + V [i]);
	}
	FOR(i,0,200000){
		chmax(dp [N] [i + 1],dp [N] [i]);
	}

	int mn = INF,mx = -INF;
	FOR(i,1,200001) if(dp [N] [i] == K){
		chmin(mn,i);
		chmax(mx,i);
	}
	if(dp [N] [200000] == K){
		printf("%d\ninf\n",mn);
	}
	else{
		printf("%d\n%d\n",mn,mx);
	}

	return 0;
}
0