結果

問題 No.286 Modulo Discount Store
ユーザー tentententen
提出日時 2021-11-11 08:31:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,648 bytes
コンパイル時間 2,723 ms
コンパイル使用メモリ 77,408 KB
実行使用メモリ 38,632 KB
最終ジャッジ日時 2024-05-01 23:47:41
合計ジャッジ時間 6,119 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
36,880 KB
testcase_01 AC 54 ms
36,828 KB
testcase_02 AC 62 ms
37,428 KB
testcase_03 AC 53 ms
36,868 KB
testcase_04 AC 55 ms
36,964 KB
testcase_05 AC 56 ms
37,056 KB
testcase_06 AC 68 ms
37,372 KB
testcase_07 AC 53 ms
36,920 KB
testcase_08 AC 54 ms
36,940 KB
testcase_09 AC 53 ms
37,016 KB
testcase_10 AC 57 ms
37,016 KB
testcase_11 AC 53 ms
36,876 KB
testcase_12 AC 53 ms
37,080 KB
testcase_13 AC 65 ms
36,584 KB
testcase_14 AC 53 ms
36,952 KB
testcase_15 AC 52 ms
36,920 KB
testcase_16 AC 53 ms
36,888 KB
testcase_17 AC 82 ms
38,632 KB
testcase_18 AC 61 ms
37,192 KB
testcase_19 AC 57 ms
36,828 KB
testcase_20 AC 55 ms
37,192 KB
testcase_21 AC 55 ms
37,036 KB
testcase_22 AC 54 ms
36,608 KB
testcase_23 AC 65 ms
37,192 KB
testcase_24 AC 53 ms
36,884 KB
testcase_25 AC 55 ms
37,056 KB
testcase_26 AC 52 ms
36,920 KB
testcase_27 AC 55 ms
36,748 KB
testcase_28 AC 82 ms
38,200 KB
testcase_29 AC 54 ms
37,192 KB
testcase_30 AC 57 ms
36,904 KB
testcase_31 AC 54 ms
36,940 KB
testcase_32 AC 53 ms
36,728 KB
testcase_33 AC 53 ms
36,608 KB
testcase_34 AC 54 ms
36,948 KB
testcase_35 AC 52 ms
36,596 KB
testcase_36 AC 53 ms
36,868 KB
testcase_37 AC 55 ms
37,004 KB
testcase_38 AC 54 ms
36,980 KB
testcase_39 AC 69 ms
37,388 KB
testcase_40 AC 58 ms
36,616 KB
testcase_41 AC 53 ms
36,968 KB
testcase_42 AC 53 ms
36,956 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] price = new int[n];
        for (int i = 0; i < n; i++) {
            price[i] = sc.nextInt();
        }
        int[] values = new int[1 << n];
        int[] costs = new int[1 << n];
        for (int i = 1; i < (1 << n); i++) {
            costs[i] = Integer.MAX_VALUE;
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) == 0) {
                    continue;
                }
                values[i] = values[i ^ (1 << j)] + price[j];
                costs[i] = Math.min(costs[i], costs[i ^ (1 << j)] + Math.max(0, price[j] - values[i ^ (1 << j)] % 1000));
            }
        }
        System.out.println(costs[(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 double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0