結果

問題 No.733 分身並列コーディング
ユーザー tentententen
提出日時 2021-05-12 18:08:50
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,721 bytes
コンパイル時間 6,263 ms
コンパイル使用メモリ 79,556 KB
実行使用メモリ 70,488 KB
最終ジャッジ日時 2023-10-24 10:46:12
合計ジャッジ時間 11,440 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,656 KB
testcase_01 AC 56 ms
52,564 KB
testcase_02 AC 57 ms
52,568 KB
testcase_03 AC 204 ms
67,580 KB
testcase_04 AC 219 ms
70,488 KB
testcase_05 AC 55 ms
53,656 KB
testcase_06 AC 56 ms
53,652 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.io.*;
import java.util.*;

public class Main {
    static ArrayList<HashMap<Integer, Integer>> dp = new ArrayList<>();
    static ArrayList<Integer> list = new ArrayList<>();
    static int[] sums;
    static int[] times;
    static int full;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int t = sc.nextInt();
        int n = sc.nextInt();
        full = (1 << n) - 1;
        times = new int[n];
        for (int i = 0; i < n; i++) {
            times[i] = sc.nextInt();
        }
        Arrays.sort(times);
        sums = new int[n];
        sums[0] = times[0];
        for (int i = 1; i < n; i++) {
            sums[i] = sums[i - 1] + times[i];
        }
        make(n - 1, t, 0);
        for (int i = 0; i < list.size(); i++) {
            dp.add(new HashMap<>());
        }
        System.out.println(dfw(list.size() - 1, 0));

    }
    
    static int dfw(int idx, int mask) {
        if (mask == full) {
            return 0;
        }
        if (idx < 0) {
            return Integer.MAX_VALUE / 2;
        }
        if (!dp.get(idx).containsKey(mask)) {
            int value = dfw(idx - 1, mask);
            if ((mask & list.get(idx)) != list.get(idx)) {
                value = Math.min(value, dfw(idx - 1, mask | list.get(idx)) + 1);
            }
            dp.get(idx).put(mask, value);
        }
        return dp.get(idx).get(mask);
    }
    
    static void make(int idx, int remain, int value) {
        if (idx < 0) {
            list.add(value);
            return;
        }
        value <<= 1;
        if (remain < times[idx]) {
            make(idx - 1, remain, value);
        } else if (remain >= sums[idx]) {
            make(idx - 1, remain - times[idx], value + 1);
        } else {
            make(idx - 1, remain, value);
            make(idx - 1, remain - times[idx], value + 1);
        }
    }
    
    static long getCount(long x, long n) {
        if (x == 1 || x > 2 * n) {
            return 0;
        } else if (x <= n) {
            return x - 1;
        } else {
            return n - (x - 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