結果

問題 No.393 2本の竹
ユーザー 37zigen37zigen
提出日時 2016-07-03 20:54:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 287 ms / 1,000 ms
コード長 1,293 bytes
コンパイル時間 1,940 ms
コンパイル使用メモリ 74,416 KB
実行使用メモリ 59,544 KB
最終ジャッジ日時 2023-08-07 23:57:22
合計ジャッジ時間 8,101 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
58,964 KB
testcase_01 AC 134 ms
58,152 KB
testcase_02 AC 143 ms
58,440 KB
testcase_03 AC 143 ms
58,312 KB
testcase_04 AC 135 ms
58,488 KB
testcase_05 AC 141 ms
58,688 KB
testcase_06 AC 134 ms
56,752 KB
testcase_07 AC 161 ms
58,644 KB
testcase_08 AC 187 ms
59,296 KB
testcase_09 AC 287 ms
59,144 KB
testcase_10 AC 200 ms
59,352 KB
testcase_11 AC 232 ms
59,524 KB
testcase_12 AC 251 ms
59,052 KB
testcase_13 AC 229 ms
59,544 KB
testcase_14 AC 179 ms
59,400 KB
testcase_15 AC 165 ms
58,556 KB
testcase_16 AC 171 ms
58,872 KB
testcase_17 AC 150 ms
58,468 KB
testcase_18 AC 143 ms
58,868 KB
testcase_19 AC 133 ms
58,568 KB
testcase_20 AC 138 ms
58,912 KB
testcase_21 AC 148 ms
58,396 KB
testcase_22 AC 194 ms
58,748 KB
testcase_23 AC 190 ms
59,108 KB
testcase_24 AC 166 ms
59,004 KB
testcase_25 AC 165 ms
58,664 KB
testcase_26 AC 132 ms
58,624 KB
testcase_27 AC 269 ms
59,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

	public static void main(String[] args) {
		int d = sc.nextInt();
		if (d <= 0 || d > 10)
			throw new AssertionError();
		for (; d > 0; d--) {
			new Main().solver();
		}
	}

	void solver() {
		int n1 = sc.nextInt();
		int n2 = sc.nextInt();
		if (n1 < 0 || n1 > 100000 || n2 < 0 || n2 > 100000) {
			throw new AssertionError();
		}
		int m = sc.nextInt();
		if (m <= 0 || m > 60)
			throw new AssertionError();
		int[] a = new int[m];
		for (int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
			if (a[i] > 100000 || a[i] <= 0)
				throw new AssertionError();
		}

		Arrays.sort(a);

		boolean[] from = new boolean[n1 + 1];
		from[0] = true;
		int len = 0;
		for (int i = 0; i < m; i++) {
			boolean[] to = new boolean[100001];
			boolean f = false;
			for (int j = 0; j <= n1; j++) {
				if (from[j]) {
					if (j + a[i] <= n1) {
						to[j + a[i]] = true;
						f = true;
					}
					if ((len - j) + a[i] <= n2) {
						to[j] = true;
						f = true;
					}
				}
			}

			len += a[i];
			from = to;

			if (!f) {
				System.out.println(i);
				return;
			}
		}
		System.out.println(m);
	}

	void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

}
0