結果

問題 No.393 2本の竹
ユーザー GrenacheGrenache
提出日時 2016-07-12 23:43:38
言語 Java19
(openjdk 21)
結果
AC  
実行時間 177 ms / 1,000 ms
コード長 2,286 bytes
コンパイル時間 3,804 ms
コンパイル使用メモリ 75,244 KB
実行使用メモリ 54,176 KB
最終ジャッジ日時 2023-08-08 00:13:47
合計ジャッジ時間 6,714 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
50,644 KB
testcase_01 AC 47 ms
49,424 KB
testcase_02 AC 54 ms
50,728 KB
testcase_03 AC 57 ms
50,472 KB
testcase_04 AC 48 ms
49,540 KB
testcase_05 AC 51 ms
49,476 KB
testcase_06 AC 49 ms
49,948 KB
testcase_07 AC 61 ms
50,424 KB
testcase_08 AC 71 ms
51,676 KB
testcase_09 AC 177 ms
54,104 KB
testcase_10 AC 67 ms
51,788 KB
testcase_11 AC 118 ms
53,340 KB
testcase_12 AC 121 ms
53,968 KB
testcase_13 AC 108 ms
54,144 KB
testcase_14 AC 81 ms
52,572 KB
testcase_15 AC 47 ms
49,488 KB
testcase_16 AC 49 ms
49,436 KB
testcase_17 AC 59 ms
50,888 KB
testcase_18 AC 57 ms
50,404 KB
testcase_19 AC 47 ms
49,484 KB
testcase_20 AC 48 ms
49,520 KB
testcase_21 AC 58 ms
50,348 KB
testcase_22 AC 122 ms
53,780 KB
testcase_23 AC 91 ms
53,312 KB
testcase_24 AC 54 ms
50,940 KB
testcase_25 AC 48 ms
49,420 KB
testcase_26 AC 46 ms
49,460 KB
testcase_27 AC 164 ms
54,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder393 {

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	Printer pr = new Printer(System.out);

    	int d = sc.nextInt();

    	for (int tcase = 0; tcase < d; tcase++) {
    		int n1 = sc.nextInt();
    		int n2 = sc.nextInt();
    		int n = n1 + n2;
    		n1 = Math.min(n1, n2);

    		int m = sc.nextInt();
    		int[] a = new int[m];
    		for (int i = 0; i < m; i++) {
    			a[i] = sc.nextInt();
    		}
    		Arrays.sort(a);

    		int[] sum = new int[m + 1];
    		for (int i = 1; i <= m; i++) {
    			sum[i] = sum[i - 1] + a[i - 1];
    		}

    		int tmp = Arrays.binarySearch(sum, n);
    		int ret = tmp >= 0 ? tmp : -(tmp + 1) - 1;
    		int ok = n1 - (n - sum[ret]);

    		BitSet bs = new BitSet(n1 + 1);
    		bs.set(0);
    		for (int i = 0; i < ret; i++) {
    			for (int j = bs.length(); (j = bs.previousSetBit(j - 1)) >= 0; ) {
    				if (j + a[i] > n1) {
    					continue;
    				} else {
    					bs.set(j + a[i]);
    				}

    			}
    		}

    		if (bs.previousSetBit(bs.length() - 1) >= ok) {
    			pr.println(ret);
    		} else {
    			pr.println(ret - 1);
    		}
    	}

		sc.close();
        pr.close();
    }

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0