結果

問題 No.733 分身並列コーディング
ユーザー htensaihtensai
提出日時 2020-01-30 16:48:58
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,503 bytes
コンパイル時間 2,258 ms
コンパイル使用メモリ 74,968 KB
実行使用メモリ 61,272 KB
最終ジャッジ日時 2023-10-14 08:31:02
合計ジャッジ時間 16,676 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,244 KB
testcase_01 AC 42 ms
49,308 KB
testcase_02 AC 43 ms
49,264 KB
testcase_03 AC 138 ms
55,704 KB
testcase_04 AC 146 ms
53,780 KB
testcase_05 AC 129 ms
59,048 KB
testcase_06 AC 43 ms
49,068 KB
testcase_07 AC 214 ms
58,468 KB
testcase_08 AC 123 ms
56,808 KB
testcase_09 AC 187 ms
53,696 KB
testcase_10 AC 103 ms
52,968 KB
testcase_11 AC 81 ms
52,140 KB
testcase_12 AC 41 ms
49,300 KB
testcase_13 AC 42 ms
49,876 KB
testcase_14 AC 139 ms
53,804 KB
testcase_15 AC 84 ms
51,652 KB
testcase_16 AC 43 ms
49,244 KB
testcase_17 AC 44 ms
49,248 KB
testcase_18 AC 136 ms
53,496 KB
testcase_19 AC 191 ms
55,192 KB
testcase_20 AC 388 ms
55,208 KB
testcase_21 AC 121 ms
52,840 KB
testcase_22 AC 402 ms
55,304 KB
testcase_23 AC 171 ms
52,792 KB
testcase_24 AC 407 ms
54,472 KB
testcase_25 AC 49 ms
49,432 KB
testcase_26 AC 42 ms
49,296 KB
testcase_27 AC 83 ms
52,376 KB
testcase_28 AC 137 ms
56,604 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 AC 172 ms
53,328 KB
testcase_33 AC 192 ms
53,208 KB
testcase_34 AC 155 ms
53,376 KB
testcase_35 AC 188 ms
53,584 KB
testcase_36 AC 162 ms
52,868 KB
testcase_37 AC 192 ms
53,712 KB
testcase_38 TLE -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] dp;
    static HashSet<Integer> ones = new HashSet<>();
    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) {
                ones.add(i);
                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 x : ones) {
            if ((x & key) != x) {
                continue;
            }
            min = Math.min(min, dfw(x ^ key) + 1);
            if (min == 2) {
                break;
            }
        }
        dp[key] = min;
        return min;
    }
}
0