結果

問題 No.733 分身並列コーディング
ユーザー tentententen
提出日時 2023-06-16 08:39:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 511 ms / 1,500 ms
コード長 2,317 bytes
コンパイル時間 2,607 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 52,252 KB
最終ジャッジ日時 2023-09-06 08:42:47
合計ジャッジ時間 15,500 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,448 KB
testcase_01 AC 43 ms
49,416 KB
testcase_02 AC 43 ms
47,404 KB
testcase_03 AC 511 ms
51,964 KB
testcase_04 AC 506 ms
51,888 KB
testcase_05 AC 55 ms
50,120 KB
testcase_06 AC 43 ms
49,392 KB
testcase_07 AC 351 ms
51,964 KB
testcase_08 AC 318 ms
52,048 KB
testcase_09 AC 206 ms
51,176 KB
testcase_10 AC 63 ms
51,728 KB
testcase_11 AC 68 ms
51,944 KB
testcase_12 AC 44 ms
49,388 KB
testcase_13 AC 43 ms
49,368 KB
testcase_14 AC 109 ms
51,852 KB
testcase_15 AC 63 ms
52,152 KB
testcase_16 AC 44 ms
49,672 KB
testcase_17 AC 43 ms
49,420 KB
testcase_18 AC 66 ms
51,920 KB
testcase_19 AC 219 ms
51,184 KB
testcase_20 AC 212 ms
50,980 KB
testcase_21 AC 110 ms
52,204 KB
testcase_22 AC 500 ms
51,108 KB
testcase_23 AC 121 ms
51,212 KB
testcase_24 AC 110 ms
51,824 KB
testcase_25 AC 44 ms
49,392 KB
testcase_26 AC 43 ms
49,440 KB
testcase_27 AC 61 ms
51,924 KB
testcase_28 AC 324 ms
51,208 KB
testcase_29 AC 501 ms
51,196 KB
testcase_30 AC 371 ms
51,884 KB
testcase_31 AC 492 ms
50,240 KB
testcase_32 AC 76 ms
51,980 KB
testcase_33 AC 75 ms
52,224 KB
testcase_34 AC 77 ms
51,860 KB
testcase_35 AC 76 ms
51,896 KB
testcase_36 AC 77 ms
51,768 KB
testcase_37 AC 77 ms
51,896 KB
testcase_38 AC 398 ms
51,912 KB
testcase_39 AC 496 ms
52,200 KB
testcase_40 AC 497 ms
50,992 KB
testcase_41 AC 77 ms
51,904 KB
testcase_42 AC 76 ms
51,848 KB
testcase_43 AC 77 ms
52,036 KB
testcase_44 AC 506 ms
51,108 KB
testcase_45 AC 499 ms
52,252 KB
testcase_46 AC 505 ms
51,212 KB
testcase_47 AC 506 ms
51,888 KB
testcase_48 AC 502 ms
51,100 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 t = sc.nextInt();
        int n = sc.nextInt();
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        int[] sum = new int[1 << n];
        int[] dp = new int[1 << n];
        for (int i = 0; i < (1 << n); i++) {
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) > 0) {
                    sum[i] = sum[i ^ (1 << j)] + values[j];
                    break;
                }
            }
            if (sum[i] <= t) {
                dp[i] = 1;
                continue;
            }
            dp[i] = Integer.MAX_VALUE;
            for (int j = i; j > 0; j = ((j - 1) & i)) {
                if (j == i) {
                    continue;
                }
                dp[i] = Math.min(dp[i], dp[i ^ j] + dp[j]);
            }
        }
        System.out.println(dp[(1 << n) - 1]);
    }
}
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