結果

問題 No.733 分身並列コーディング
ユーザー htensaihtensai
提出日時 2020-01-30 16:34:28
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,472 bytes
コンパイル時間 2,404 ms
コンパイル使用メモリ 75,128 KB
実行使用メモリ 69,148 KB
最終ジャッジ日時 2023-10-14 08:30:28
合計ジャッジ時間 6,528 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,696 KB
testcase_01 AC 37 ms
49,368 KB
testcase_02 AC 39 ms
49,320 KB
testcase_03 AC 321 ms
65,352 KB
testcase_04 AC 331 ms
65,216 KB
testcase_05 AC 131 ms
61,508 KB
testcase_06 AC 38 ms
49,636 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
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 {
    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());
        }
        HashSet<Integer>[] dp= new HashSet[n];
        dp[0] = new HashSet<>();
        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[0].add(i);
            }
        }
        for (int i = 1; i <= n; i++) {
            if (dp[i - 1].contains((1 << n) - 1)) {
                System.out.println(i);
                return;
            }
            dp[i] = new HashSet<>();
            for (int x : dp[i - 1]) {
                for (int y : dp[0]) {
                    if ((x & y) != 0) {
                        continue;
                    }
                    if (!dp[i - 1].contains(x | y)) {
                        dp[i].add(x | y);
                    }
                }
            }
        }
    }
}
0