結果

問題 No.733 分身並列コーディング
ユーザー tentententen
提出日時 2021-05-13 11:51:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 337 ms / 1,500 ms
コード長 1,532 bytes
コンパイル時間 2,197 ms
コンパイル使用メモリ 77,804 KB
実行使用メモリ 56,704 KB
最終ジャッジ日時 2023-10-25 05:56:10
合計ジャッジ時間 12,215 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
53,232 KB
testcase_01 AC 57 ms
53,224 KB
testcase_02 AC 55 ms
53,232 KB
testcase_03 AC 331 ms
54,652 KB
testcase_04 AC 285 ms
54,896 KB
testcase_05 AC 337 ms
54,916 KB
testcase_06 AC 57 ms
53,224 KB
testcase_07 AC 307 ms
55,152 KB
testcase_08 AC 302 ms
54,700 KB
testcase_09 AC 174 ms
56,704 KB
testcase_10 AC 82 ms
54,800 KB
testcase_11 AC 81 ms
54,836 KB
testcase_12 AC 56 ms
53,220 KB
testcase_13 AC 56 ms
53,220 KB
testcase_14 AC 103 ms
54,768 KB
testcase_15 AC 68 ms
53,856 KB
testcase_16 AC 56 ms
53,248 KB
testcase_17 AC 56 ms
53,240 KB
testcase_18 AC 84 ms
54,768 KB
testcase_19 AC 151 ms
54,792 KB
testcase_20 AC 151 ms
54,780 KB
testcase_21 AC 104 ms
54,800 KB
testcase_22 AC 285 ms
54,808 KB
testcase_23 AC 105 ms
54,888 KB
testcase_24 AC 109 ms
54,772 KB
testcase_25 AC 56 ms
53,236 KB
testcase_26 AC 55 ms
53,172 KB
testcase_27 AC 85 ms
52,412 KB
testcase_28 AC 307 ms
54,780 KB
testcase_29 AC 289 ms
54,788 KB
testcase_30 AC 286 ms
54,892 KB
testcase_31 AC 287 ms
54,828 KB
testcase_32 AC 87 ms
54,740 KB
testcase_33 AC 89 ms
54,740 KB
testcase_34 AC 86 ms
54,848 KB
testcase_35 AC 88 ms
54,776 KB
testcase_36 AC 94 ms
54,828 KB
testcase_37 AC 87 ms
54,796 KB
testcase_38 AC 289 ms
54,940 KB
testcase_39 AC 289 ms
54,896 KB
testcase_40 AC 299 ms
54,872 KB
testcase_41 AC 89 ms
54,748 KB
testcase_42 AC 89 ms
54,764 KB
testcase_43 AC 89 ms
54,760 KB
testcase_44 AC 289 ms
54,952 KB
testcase_45 AC 291 ms
54,800 KB
testcase_46 AC 294 ms
54,748 KB
testcase_47 AC 288 ms
54,912 KB
testcase_48 AC 289 ms
54,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int t = sc.nextInt();
        int n = sc.nextInt();
        int[] times = new int[n];
        for (int i = 0; i < n; i++) {
            times[i] = sc.nextInt();
        }
        int[] dp = new int[1 << n];
        Arrays.fill(dp, Integer.MAX_VALUE / 2);
        for (int i = 1; i < 1 << n; i++) {
            int total = 0;
            for (int j = 0; j < n && total <= t; j++) {
                if ((i & (1 << j)) == 0) {
                    continue;
                }
                total += times[j];
            }
            if (total <= t) {
                dp[i] = 1;
            }
            for (int j = i; j > 0; j = ((j - 1) & i)) {
                dp[i] = Math.min(dp[i], dp[j] + dp[i ^ j]);
            }
        }
        System.out.println(dp[(1 << n) - 1]);
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0