結果

問題 No.393 2本の竹
ユーザー sekiya9311sekiya9311
提出日時 2016-08-26 15:36:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 415 ms / 1,000 ms
コード長 948 bytes
コンパイル時間 3,152 ms
コンパイル使用メモリ 78,384 KB
実行使用メモリ 100,936 KB
最終ジャッジ日時 2024-04-25 21:30:03
合計ジャッジ時間 9,192 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
54,404 KB
testcase_01 AC 119 ms
54,264 KB
testcase_02 AC 128 ms
54,292 KB
testcase_03 AC 140 ms
54,128 KB
testcase_04 AC 127 ms
54,136 KB
testcase_05 AC 133 ms
54,292 KB
testcase_06 AC 131 ms
54,380 KB
testcase_07 AC 157 ms
54,220 KB
testcase_08 AC 171 ms
56,732 KB
testcase_09 AC 415 ms
100,936 KB
testcase_10 AC 207 ms
67,160 KB
testcase_11 AC 218 ms
69,896 KB
testcase_12 AC 248 ms
68,524 KB
testcase_13 AC 208 ms
62,396 KB
testcase_14 AC 194 ms
64,064 KB
testcase_15 AC 178 ms
65,828 KB
testcase_16 AC 199 ms
73,880 KB
testcase_17 AC 145 ms
54,284 KB
testcase_18 AC 134 ms
54,536 KB
testcase_19 AC 119 ms
54,208 KB
testcase_20 AC 120 ms
53,548 KB
testcase_21 AC 140 ms
54,484 KB
testcase_22 AC 252 ms
72,892 KB
testcase_23 AC 233 ms
65,412 KB
testcase_24 AC 150 ms
56,612 KB
testcase_25 AC 154 ms
54,452 KB
testcase_26 AC 124 ms
54,280 KB
testcase_27 AC 362 ms
86,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Yuki393 {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int d = sc.nextInt();
		for (int i = 0; i < d; i++) {
			System.out.println(solve());
		}
	}

	static int solve() {
		int n1, n2;
		n1 = sc.nextInt();
		n2 = sc.nextInt();
		int m = sc.nextInt();
		int[] A = new int[m];
		for (int i = 0; i < m; i++) {
			A[i] = sc.nextInt();
		}
		Arrays.sort(A);
		int[][] dp = new int[m + 1][n1 + 1];
		for (int i = 0; i < m + 1; i++) {
			Arrays.fill(dp[i], -1);
		}
		dp[0][n1] = n2;
		for (int i = 0; i < m; i++) {
			boolean f = false;
			for (int j = 0; j < dp[i].length; j++) {
				if (dp[i][j] == -1)
					continue;
				if (dp[i][j] - A[i] >= 0) {
					dp[i + 1][j] = dp[i][j] - A[i];
					f = true;
				}
				if (j - A[i] >= 0) {
					dp[i + 1][j - A[i]] = dp[i][j];
					f = true;
				}
			}
			if (!f)
				return i;
		}
		return m;
	}
}
0