結果

問題 No.733 分身並列コーディング
ユーザー htensaihtensai
提出日時 2020-01-30 16:59:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 776 ms / 1,500 ms
コード長 1,390 bytes
コンパイル時間 1,755 ms
コンパイル使用メモリ 74,120 KB
実行使用メモリ 52,876 KB
最終ジャッジ日時 2023-10-14 08:31:57
合計ジャッジ時間 15,929 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
49,160 KB
testcase_01 AC 37 ms
49,064 KB
testcase_02 AC 37 ms
49,100 KB
testcase_03 AC 707 ms
50,404 KB
testcase_04 AC 732 ms
49,916 KB
testcase_05 AC 62 ms
51,524 KB
testcase_06 AC 37 ms
49,140 KB
testcase_07 AC 73 ms
52,384 KB
testcase_08 AC 63 ms
51,568 KB
testcase_09 AC 278 ms
51,820 KB
testcase_10 AC 67 ms
51,632 KB
testcase_11 AC 66 ms
51,040 KB
testcase_12 AC 37 ms
49,172 KB
testcase_13 AC 35 ms
47,396 KB
testcase_14 AC 132 ms
51,848 KB
testcase_15 AC 56 ms
51,112 KB
testcase_16 AC 43 ms
49,724 KB
testcase_17 AC 41 ms
49,068 KB
testcase_18 AC 64 ms
51,156 KB
testcase_19 AC 279 ms
51,912 KB
testcase_20 AC 276 ms
51,992 KB
testcase_21 AC 133 ms
52,092 KB
testcase_22 AC 776 ms
52,368 KB
testcase_23 AC 135 ms
51,784 KB
testcase_24 AC 131 ms
51,800 KB
testcase_25 AC 39 ms
49,100 KB
testcase_26 AC 37 ms
49,288 KB
testcase_27 AC 62 ms
51,408 KB
testcase_28 AC 79 ms
52,308 KB
testcase_29 AC 678 ms
51,816 KB
testcase_30 AC 671 ms
51,588 KB
testcase_31 AC 628 ms
52,876 KB
testcase_32 AC 79 ms
51,556 KB
testcase_33 AC 82 ms
51,740 KB
testcase_34 AC 81 ms
52,088 KB
testcase_35 AC 82 ms
51,752 KB
testcase_36 AC 80 ms
51,580 KB
testcase_37 AC 80 ms
51,596 KB
testcase_38 AC 637 ms
51,468 KB
testcase_39 AC 623 ms
51,856 KB
testcase_40 AC 553 ms
51,840 KB
testcase_41 AC 82 ms
51,964 KB
testcase_42 AC 77 ms
51,336 KB
testcase_43 AC 83 ms
51,660 KB
testcase_44 AC 664 ms
51,880 KB
testcase_45 AC 646 ms
51,464 KB
testcase_46 AC 632 ms
51,672 KB
testcase_47 AC 634 ms
51,876 KB
testcase_48 AC 647 ms
52,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] dp;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(br.readLine());
        int n = Integer.parseInt(br.readLine());
        int[] times = new int[n];
        for (int i = 0; i < n; i++) {
            times[i] = Integer.parseInt(br.readLine());
        }
        dp = new int[1 << n];
        for (int i = 1; i < (1 << n); i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) == 0) {
                    continue;
                }
                sum += times[j];
                if (sum > t) {
                    break;
                }
            }
            if (sum <= t) {
                dp[i] = 1;
            }
        }
        System.out.println(dfw((1 << n) - 1));
    }
    
    static int dfw(int key) {
        if (key == 0) {
            return 0;
        }
        if (dp[key] != 0) {
            return dp[key];
        }
        int min = Integer.MAX_VALUE;
        for (int i = (key - 1) & key; i > 0; i = (i - 1) & key) {
            min = Math.min(min, dfw(i) + dfw(key ^ i));
            if (min == 2) {
                break;
            }
        }
        dp[key] = min;
        return min;
    }
}
0