結果

問題 No.527 ナップサック容量問題
ユーザー YamyukiYamyuki
提出日時 2017-06-09 23:45:54
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 635 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 22,216 KB
実行使用メモリ 79,740 KB
最終ジャッジ日時 2023-10-24 02:30:31
合計ジャッジ時間 2,042 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
6,380 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
6,380 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 13 ms
33,004 KB
testcase_06 AC 28 ms
69,868 KB
testcase_07 AC 20 ms
55,528 KB
testcase_08 AC 11 ms
28,904 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 25 ms
69,868 KB
testcase_11 AC 18 ms
49,388 KB
testcase_12 AC 14 ms
37,100 KB
testcase_13 AC 26 ms
71,916 KB
testcase_14 AC 10 ms
26,860 KB
testcase_15 AC 15 ms
41,196 KB
testcase_16 AC 2 ms
6,380 KB
testcase_17 AC 13 ms
35,052 KB
testcase_18 AC 15 ms
39,148 KB
testcase_19 AC 3 ms
6,380 KB
testcase_20 AC 10 ms
28,908 KB
testcase_21 AC 31 ms
79,740 KB
testcase_22 AC 20 ms
53,484 KB
testcase_23 AC 28 ms
78,060 KB
testcase_24 AC 7 ms
16,620 KB
testcase_25 AC 19 ms
53,484 KB
testcase_26 AC 17 ms
47,340 KB
testcase_27 AC 18 ms
47,340 KB
testcase_28 AC 15 ms
41,196 KB
testcase_29 AC 29 ms
78,956 KB
testcase_30 AC 4 ms
10,476 KB
testcase_31 AC 13 ms
35,052 KB
testcase_32 AC 15 ms
43,244 KB
testcase_33 AC 13 ms
37,100 KB
testcase_34 AC 17 ms
45,292 KB
testcase_35 AC 16 ms
45,292 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 12 ms
33,004 KB
testcase_38 AC 16 ms
43,244 KB
testcase_39 AC 15 ms
39,148 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d",&n);
      |         ^~~~~~~~~~~~~~
main.c:9:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |                 scanf("%ld %ld",&v[i],&w[i]);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:11:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%ld",&V);
      |         ^~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#define max(a,b) (((a)>(b))?(a):(b))
long dp[100][100001],v[100],w[100];
int main(int argc, char const *argv[]){
	int n,i,f=0;
	long V,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%ld %ld",&v[i],&w[i]);
	}
	scanf("%ld",&V);
	for(j=w[0];j<=100000;j++){
		dp[0][j]=v[0];
	}
	for(i=1;i<n;i++){
		for(j=0;j<=100000;j++){
			dp[i][j]=dp[i-1][j];
			if(j>=w[i]) dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
		}
	}
	for(j=1;j<=100000;j++){
		if(f==0 && dp[n-1][j]==V){
			printf("%ld\n",j);
			f=1;
		}else if(f==1 && dp[n-1][j]>V){
			f=2;
			printf("%ld\n",j-1);
			break;
		}
	}
	if(f==1) printf("inf\n");
	return 0;
}
0