結果

問題 No.393 2本の竹
ユーザー tentententen
提出日時 2023-05-02 14:49:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 208 ms / 1,000 ms
コード長 2,698 bytes
コンパイル時間 2,737 ms
コンパイル使用メモリ 81,112 KB
実行使用メモリ 65,624 KB
最終ジャッジ日時 2023-08-13 11:05:03
合計ジャッジ時間 6,221 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,588 KB
testcase_01 AC 46 ms
49,496 KB
testcase_02 AC 46 ms
49,408 KB
testcase_03 AC 47 ms
49,504 KB
testcase_04 AC 44 ms
49,464 KB
testcase_05 AC 45 ms
49,524 KB
testcase_06 AC 44 ms
47,548 KB
testcase_07 AC 49 ms
49,480 KB
testcase_08 AC 61 ms
51,268 KB
testcase_09 AC 208 ms
63,076 KB
testcase_10 AC 53 ms
52,416 KB
testcase_11 AC 72 ms
54,208 KB
testcase_12 AC 85 ms
57,120 KB
testcase_13 AC 73 ms
54,540 KB
testcase_14 AC 54 ms
52,056 KB
testcase_15 AC 46 ms
49,996 KB
testcase_16 AC 52 ms
52,256 KB
testcase_17 AC 46 ms
49,584 KB
testcase_18 AC 45 ms
49,488 KB
testcase_19 AC 45 ms
49,672 KB
testcase_20 AC 45 ms
49,524 KB
testcase_21 AC 47 ms
49,720 KB
testcase_22 AC 76 ms
58,292 KB
testcase_23 AC 75 ms
53,980 KB
testcase_24 AC 47 ms
49,464 KB
testcase_25 AC 46 ms
49,400 KB
testcase_26 AC 45 ms
49,472 KB
testcase_27 AC 173 ms
65,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int d = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        while (d-- > 0) {
            int n1 = sc.nextInt();
            int n2 = sc.nextInt();
            int length = sc.nextInt();
            int[] values = new int[length];
            for (int i = 0; i < length; i++) {
                values[i] = sc.nextInt();
            }
            Arrays.sort(values);
            int left = 0;
            int right = length + 1;
            while (right - left > 1) {
                int m = (left + right) / 2;
                boolean[][] dp = new boolean[m][n1 + 1];
                if (dfw(m - 1, n1, n2, values, dp)) {
                    right = m;
                } else {
                    left = m;
                }
            }
            sb.append(left).append("\n");
        }
        System.out.print(sb);
    }
    
    static boolean dfw(int idx, int left, int right, int[] values, boolean[][] dp) {
        if (left < 0 || right < 0) {
            return true;
        }
        if (idx < 0) {
            return false;
        }
        if (!dp[idx][left]) {
            dp[idx][left] = (dfw(idx - 1, left - values[idx], right, values, dp) && dfw(idx - 1, left, right - values[idx], values, dp));
        }
        return dp[idx][left];
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0