結果

問題 No.5 数字のブロック
ユーザー uafr_csuafr_cs
提出日時 2015-04-30 03:49:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 397 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 71,536 KB
実行使用メモリ 60,672 KB
最終ジャッジ日時 2023-08-11 08:18:53
合計ジャッジ時間 11,025 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,052 KB
testcase_01 AC 121 ms
55,656 KB
testcase_02 AC 120 ms
55,644 KB
testcase_03 AC 349 ms
59,912 KB
testcase_04 AC 215 ms
59,632 KB
testcase_05 AC 354 ms
60,672 KB
testcase_06 AC 316 ms
60,268 KB
testcase_07 AC 321 ms
59,988 KB
testcase_08 AC 312 ms
60,540 KB
testcase_09 AC 239 ms
58,148 KB
testcase_10 AC 334 ms
60,564 KB
testcase_11 AC 303 ms
60,264 KB
testcase_12 AC 344 ms
59,832 KB
testcase_13 AC 329 ms
60,464 KB
testcase_14 AC 143 ms
55,996 KB
testcase_15 AC 150 ms
55,784 KB
testcase_16 AC 347 ms
60,300 KB
testcase_17 AC 386 ms
60,432 KB
testcase_18 AC 344 ms
60,136 KB
testcase_19 AC 397 ms
60,412 KB
testcase_20 AC 123 ms
55,652 KB
testcase_21 AC 123 ms
56,216 KB
testcase_22 AC 122 ms
55,928 KB
testcase_23 AC 122 ms
55,336 KB
testcase_24 AC 153 ms
55,888 KB
testcase_25 AC 214 ms
56,676 KB
testcase_26 AC 124 ms
55,920 KB
testcase_27 AC 122 ms
55,988 KB
testcase_28 AC 121 ms
56,236 KB
testcase_29 AC 208 ms
58,908 KB
testcase_30 AC 219 ms
59,136 KB
testcase_31 AC 123 ms
56,064 KB
testcase_32 AC 122 ms
56,028 KB
testcase_33 AC 123 ms
55,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int L = sc.nextInt();
		final int N = sc.nextInt();
		
		int[] ws = new int[N];
		for(int i = 0; i < N; i++){
			ws[i] = sc.nextInt();
		}
		
		int[] DP = new int[L + 1];
		Arrays.fill(DP, -1);
		DP[0] = 0;
		
		int max = Integer.MIN_VALUE;
		for(final int weight : ws){
			for(int current = L - weight; current >= 0; current--){
				if(DP[current] < 0){
					continue;
				}
				
				DP[weight + current] = Math.max(DP[weight + current], DP[current] + 1);
				max = Math.max(max, DP[weight + current]);
			}
		}
		
		System.out.println(max);
	}
	
}
0