結果

問題 No.393 2本の竹
ユーザー 37zigen37zigen
提出日時 2016-07-03 20:38:44
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 272 ms / 1,000 ms
コード長 1,003 bytes
コンパイル時間 2,037 ms
使用メモリ 47,200 KB
最終ジャッジ日時 2022-12-14 14:06:49
合計ジャッジ時間 7,173 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 123 ms
45,804 KB
testcase_01 AC 104 ms
43,872 KB
testcase_02 AC 118 ms
45,868 KB
testcase_03 AC 115 ms
43,660 KB
testcase_04 AC 110 ms
43,988 KB
testcase_05 AC 113 ms
43,788 KB
testcase_06 AC 104 ms
44,072 KB
testcase_07 AC 119 ms
43,836 KB
testcase_08 AC 139 ms
44,532 KB
testcase_09 AC 272 ms
46,244 KB
testcase_10 AC 143 ms
45,124 KB
testcase_11 AC 166 ms
45,120 KB
testcase_12 AC 168 ms
47,200 KB
testcase_13 AC 163 ms
46,996 KB
testcase_14 AC 143 ms
45,000 KB
testcase_15 AC 128 ms
43,216 KB
testcase_16 AC 143 ms
44,592 KB
testcase_17 AC 118 ms
43,888 KB
testcase_18 AC 114 ms
45,668 KB
testcase_19 AC 107 ms
43,080 KB
testcase_20 AC 117 ms
45,752 KB
testcase_21 AC 118 ms
45,784 KB
testcase_22 AC 175 ms
44,436 KB
testcase_23 AC 150 ms
47,148 KB
testcase_24 AC 132 ms
46,956 KB
testcase_25 AC 111 ms
46,180 KB
testcase_26 AC 104 ms
41,688 KB
testcase_27 AC 256 ms
46,140 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();
		for(;d>0;d--){
			new Main().solver();
		}
	}

	void solver() {
		int n1 = sc.nextInt();
		int 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);
		

		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