結果

問題 No.527 ナップサック容量問題
ユーザー autumn-eelautumn-eel
提出日時 2017-09-09 08:39:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 585 bytes
コンパイル時間 1,767 ms
コンパイル使用メモリ 162,948 KB
実行使用メモリ 160,128 KB
最終ジャッジ日時 2024-04-24 23:08:27
合計ジャッジ時間 8,233 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
160,000 KB
testcase_01 AC 119 ms
159,872 KB
testcase_02 AC 118 ms
160,128 KB
testcase_03 AC 120 ms
160,128 KB
testcase_04 AC 120 ms
159,872 KB
testcase_05 AC 123 ms
159,872 KB
testcase_06 AC 132 ms
160,000 KB
testcase_07 AC 131 ms
160,128 KB
testcase_08 AC 126 ms
159,872 KB
testcase_09 AC 119 ms
160,000 KB
testcase_10 AC 133 ms
160,000 KB
testcase_11 AC 126 ms
160,000 KB
testcase_12 AC 127 ms
160,000 KB
testcase_13 AC 130 ms
160,000 KB
testcase_14 AC 123 ms
159,872 KB
testcase_15 AC 127 ms
160,000 KB
testcase_16 AC 119 ms
160,000 KB
testcase_17 AC 124 ms
160,000 KB
testcase_18 AC 127 ms
159,872 KB
testcase_19 AC 119 ms
159,872 KB
testcase_20 AC 122 ms
159,872 KB
testcase_21 AC 132 ms
160,000 KB
testcase_22 AC 128 ms
160,000 KB
testcase_23 AC 133 ms
160,128 KB
testcase_24 AC 122 ms
159,872 KB
testcase_25 AC 129 ms
160,000 KB
testcase_26 AC 126 ms
160,128 KB
testcase_27 AC 127 ms
160,000 KB
testcase_28 AC 126 ms
159,872 KB
testcase_29 AC 134 ms
160,000 KB
testcase_30 AC 121 ms
159,872 KB
testcase_31 AC 124 ms
159,872 KB
testcase_32 AC 126 ms
160,000 KB
testcase_33 AC 125 ms
159,872 KB
testcase_34 AC 126 ms
160,128 KB
testcase_35 AC 127 ms
159,872 KB
testcase_36 AC 122 ms
160,000 KB
testcase_37 AC 124 ms
160,128 KB
testcase_38 AC 127 ms
160,000 KB
testcase_39 AC 127 ms
160,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
using namespace std;

int dp[200][200000];//i番目までで価値jを作る最小の重さ
int v[200],w[200];
int main() {
	int n;scanf("%d",&n);
	rep(i,n)scanf("%d%d",&v[i],&w[i]);
	int V;scanf("%d",&V);
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	rep(i,n)rep(j,100000){
		dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
		dp[i+1][j+v[i]]=min(dp[i+1][j+v[i]],dp[i][j]+w[i]);
	}
	printf("%d\n",max(1,dp[n][V]));
	int a=*min_element(dp[n]+V+1,dp[n]+200000);
	if(a==INF)puts("inf");
	else printf("%d\n",a-1);
}
0