結果

問題 No.527 ナップサック容量問題
ユーザー tailstails
提出日時 2017-06-09 22:42:09
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 452 bytes
コンパイル時間 870 ms
コンパイル使用メモリ 28,928 KB
実行使用メモリ 44,840 KB
最終ジャッジ日時 2024-09-22 15:33:02
合計ジャッジ時間 1,676 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 46 ms
44,800 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 48 ms
44,764 KB
testcase_06 AC 39 ms
44,760 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 46 ms
44,764 KB
testcase_09 AC 46 ms
44,800 KB
testcase_10 AC 13 ms
15,368 KB
testcase_11 AC 40 ms
44,820 KB
testcase_12 AC 41 ms
44,840 KB
testcase_13 AC 38 ms
44,772 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 8 ms
8,400 KB
testcase_18 AC 9 ms
9,520 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 1 ms
6,944 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 1 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 1 ms
6,944 KB
testcase_29 AC 1 ms
6,944 KB
testcase_30 AC 43 ms
44,808 KB
testcase_31 AC 1 ms
6,940 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 1 ms
6,940 KB
testcase_34 AC 1 ms
6,940 KB
testcase_35 AC 8 ms
9,704 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 5 ms
6,940 KB
testcase_39 AC 8 ms
9,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:1:1: warning: data definition has no type or storage class
    1 | v[110];
      | ^
main.c:1:1: warning: type defaults to 'int' in declaration of 'v' [-Wimplicit-int]
main.c:2:1: warning: data definition has no type or storage class
    2 | w[110];
      | ^
main.c:2:1: warning: type defaults to 'int' in declaration of 'w' [-Wimplicit-int]
main.c:3:1: warning: data definition has no type or storage class
    3 | n;k;
      | ^
main.c:3:1: warning: type defaults to 'int' in declaration of 'n' [-Wimplicit-int]
main.c:3:3: warning: data definition has no type or storage class
    3 | n;k;
      |   ^
main.c:3:3: warning: type defaults to 'int' in declaration of 'k' [-Wimplicit-int]
main.c:4:1: warning: data definition has no type or storage class
    4 | d[100010][110];
      | ^
main.c:4:1: warning: type defaults to 'int' in declaration of 'd' [-Wimplicit-int]
main.c:5:1: warning: data definition has no type or storage class
    5 | f;
      | ^
main.c:5:1: warning: type defaults to 'int' in declaration of 'f' [-Wimplicit-int]
main.c:7:1: warning: return type defaults to 'int' [-Wimplicit-int]
    7 | main(){
      | ^~~~
main.c: In function 'main':
main.c:8:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
    8 |         scanf("%d",&n);
      |         ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | v[110];
main.c:8:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
    8 |         scanf("%d",&n);
      |         ^~~~~
main.c:8:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:24:25: warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
   24 |                         printf("%d\n",c-1);
      |                         ^~~~~~
main.c:24:25: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:24:25: warning: incompatible implicit de

ソースコード

diff #

v[110];
w[110];
n;k;
d[100010][110];
f;

main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i){
		scanf("%d%d",v+i,w+i);
	}
	scanf("%d",&k);
	for(int c=1;c<100000;++c){
		for(int i=0;i<n;++i){
			if(i>0){
				d[c][i]=d[c][i-1];
			}
			if(c-w[i]>=0){
				int d1=d[c-w[i]][i-1]+v[i];
				if(d[c][i]<d1)d[c][i]=d1;
			}
		}
		if(f&&d[c][n-1]>k){
			printf("%d\n",c-1);
			exit(0);
		}
		if(!f&&d[c][n-1]==k){
			printf("%d\n",c);
			f=1;
		}
	}
	puts("inf");
}
0