結果

問題 No.5 数字のブロック
ユーザー uafr_csuafr_cs
提出日時 2015-04-30 03:49:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 373 ms / 5,000 ms
コード長 714 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 74,864 KB
実行使用メモリ 58,792 KB
最終ジャッジ日時 2024-04-29 00:53:05
合計ジャッジ時間 9,713 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
52,560 KB
testcase_01 AC 117 ms
53,836 KB
testcase_02 AC 109 ms
53,700 KB
testcase_03 AC 336 ms
58,504 KB
testcase_04 AC 212 ms
57,740 KB
testcase_05 AC 366 ms
58,484 KB
testcase_06 AC 302 ms
58,464 KB
testcase_07 AC 243 ms
57,676 KB
testcase_08 AC 296 ms
58,436 KB
testcase_09 AC 217 ms
56,608 KB
testcase_10 AC 302 ms
58,752 KB
testcase_11 AC 264 ms
58,628 KB
testcase_12 AC 309 ms
58,620 KB
testcase_13 AC 308 ms
58,792 KB
testcase_14 AC 135 ms
53,984 KB
testcase_15 AC 143 ms
53,992 KB
testcase_16 AC 320 ms
58,780 KB
testcase_17 AC 352 ms
58,668 KB
testcase_18 AC 302 ms
58,508 KB
testcase_19 AC 373 ms
58,496 KB
testcase_20 AC 110 ms
53,432 KB
testcase_21 AC 118 ms
54,112 KB
testcase_22 AC 103 ms
52,912 KB
testcase_23 AC 104 ms
53,056 KB
testcase_24 AC 135 ms
53,964 KB
testcase_25 AC 194 ms
54,564 KB
testcase_26 AC 102 ms
52,568 KB
testcase_27 AC 102 ms
53,008 KB
testcase_28 AC 112 ms
53,820 KB
testcase_29 AC 200 ms
57,080 KB
testcase_30 AC 193 ms
56,880 KB
testcase_31 AC 113 ms
54,060 KB
testcase_32 AC 112 ms
53,796 KB
testcase_33 AC 112 ms
54,232 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