結果

問題 No.286 Modulo Discount Store
ユーザー htensaihtensai
提出日時 2020-02-07 09:24:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 3,320 ms
コンパイル使用メモリ 77,396 KB
実行使用メモリ 54,824 KB
最終ジャッジ日時 2023-10-25 23:01:20
合計ジャッジ時間 6,317 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,284 KB
testcase_01 AC 55 ms
53,288 KB
testcase_02 AC 63 ms
53,840 KB
testcase_03 AC 53 ms
53,304 KB
testcase_04 AC 53 ms
51,352 KB
testcase_05 AC 54 ms
53,292 KB
testcase_06 AC 80 ms
54,668 KB
testcase_07 AC 54 ms
53,296 KB
testcase_08 AC 54 ms
53,292 KB
testcase_09 AC 53 ms
53,288 KB
testcase_10 AC 60 ms
53,292 KB
testcase_11 AC 53 ms
53,300 KB
testcase_12 AC 53 ms
53,304 KB
testcase_13 AC 62 ms
53,944 KB
testcase_14 AC 54 ms
53,296 KB
testcase_15 AC 54 ms
53,292 KB
testcase_16 AC 53 ms
53,296 KB
testcase_17 AC 82 ms
54,824 KB
testcase_18 AC 59 ms
53,296 KB
testcase_19 AC 54 ms
53,292 KB
testcase_20 AC 56 ms
53,300 KB
testcase_21 AC 54 ms
53,288 KB
testcase_22 AC 54 ms
53,292 KB
testcase_23 AC 65 ms
52,740 KB
testcase_24 AC 55 ms
53,284 KB
testcase_25 AC 60 ms
53,300 KB
testcase_26 AC 55 ms
52,208 KB
testcase_27 AC 56 ms
53,296 KB
testcase_28 AC 80 ms
54,672 KB
testcase_29 AC 54 ms
53,284 KB
testcase_30 AC 53 ms
53,304 KB
testcase_31 AC 53 ms
53,292 KB
testcase_32 AC 58 ms
53,296 KB
testcase_33 AC 54 ms
53,300 KB
testcase_34 AC 54 ms
53,296 KB
testcase_35 AC 53 ms
53,308 KB
testcase_36 AC 56 ms
53,296 KB
testcase_37 AC 58 ms
53,300 KB
testcase_38 AC 55 ms
53,288 KB
testcase_39 AC 78 ms
54,700 KB
testcase_40 AC 53 ms
53,292 KB
testcase_41 AC 53 ms
53,288 KB
testcase_42 AC 51 ms
53,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int n;
    static int[] prices;
    static int[] dp;
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n = Integer.parseInt(br.readLine());
        prices = new int[n];
        for (int i = 0; i < n; i++) {
            prices[i] = Integer.parseInt(br.readLine());
        }
        dp = new int[1 << n];
        System.out.println(dfw((1 << n) - 1));
   }
   
   static int dfw(int key) {
       if (key == 0) {
           return 0;
       }
       if (dp[key] != 0) {
           return dp[key];
       }
       int sum = 0;
       for (int i = 0; i < n; i++) {
           if (((1 << i) & key) != 0) {
               sum += prices[i];
           }
       }
       int min = Integer.MAX_VALUE;
       for (int i = 0; i < n; i++) {
           if (((1 << i) & key) == 0) {
               continue;
           }
           min = Math.min(min, dfw(key ^ (1 << i)) + prices[i] - Math.min(prices[i], (sum - prices[i]) % 1000));
       }
       dp[key] = min;
       return min;
   }
}
0