結果

問題 No.393 2本の竹
ユーザー 37zigen37zigen
提出日時 2016-07-03 20:54:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 280 ms / 1,000 ms
コード長 1,293 bytes
コンパイル時間 2,465 ms
コンパイル使用メモリ 78,084 KB
実行使用メモリ 58,264 KB
最終ジャッジ日時 2024-04-25 18:06:20
合計ジャッジ時間 7,749 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 165 ms
57,224 KB
testcase_01 AC 122 ms
56,812 KB
testcase_02 AC 136 ms
57,080 KB
testcase_03 AC 143 ms
57,024 KB
testcase_04 AC 136 ms
57,060 KB
testcase_05 AC 140 ms
56,948 KB
testcase_06 AC 126 ms
56,740 KB
testcase_07 AC 150 ms
57,044 KB
testcase_08 AC 174 ms
57,552 KB
testcase_09 AC 280 ms
57,548 KB
testcase_10 AC 183 ms
57,656 KB
testcase_11 AC 222 ms
57,812 KB
testcase_12 AC 245 ms
57,816 KB
testcase_13 AC 210 ms
57,788 KB
testcase_14 AC 193 ms
57,704 KB
testcase_15 AC 142 ms
56,516 KB
testcase_16 AC 173 ms
57,288 KB
testcase_17 AC 140 ms
57,436 KB
testcase_18 AC 136 ms
57,152 KB
testcase_19 AC 138 ms
57,004 KB
testcase_20 AC 138 ms
57,120 KB
testcase_21 AC 138 ms
56,892 KB
testcase_22 AC 192 ms
57,436 KB
testcase_23 AC 191 ms
58,264 KB
testcase_24 AC 160 ms
57,284 KB
testcase_25 AC 171 ms
57,724 KB
testcase_26 AC 133 ms
57,228 KB
testcase_27 AC 260 ms
58,016 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