結果

問題 No.286 Modulo Discount Store
ユーザー tentententen
提出日時 2020-10-07 09:52:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 1,861 ms
コンパイル使用メモリ 73,972 KB
実行使用メモリ 56,648 KB
最終ジャッジ日時 2023-09-27 09:09:24
合計ジャッジ時間 8,882 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
56,340 KB
testcase_01 AC 112 ms
53,504 KB
testcase_02 AC 130 ms
56,388 KB
testcase_03 AC 111 ms
56,320 KB
testcase_04 AC 111 ms
55,532 KB
testcase_05 AC 109 ms
55,860 KB
testcase_06 AC 130 ms
56,452 KB
testcase_07 AC 111 ms
56,160 KB
testcase_08 AC 115 ms
56,340 KB
testcase_09 AC 110 ms
55,896 KB
testcase_10 AC 123 ms
56,152 KB
testcase_11 AC 111 ms
56,172 KB
testcase_12 AC 108 ms
55,964 KB
testcase_13 AC 126 ms
56,092 KB
testcase_14 AC 115 ms
56,644 KB
testcase_15 AC 112 ms
55,908 KB
testcase_16 AC 109 ms
55,900 KB
testcase_17 AC 132 ms
56,648 KB
testcase_18 AC 127 ms
55,956 KB
testcase_19 AC 112 ms
56,172 KB
testcase_20 AC 125 ms
55,868 KB
testcase_21 AC 114 ms
55,720 KB
testcase_22 AC 109 ms
56,436 KB
testcase_23 AC 123 ms
56,392 KB
testcase_24 AC 112 ms
56,172 KB
testcase_25 AC 126 ms
56,384 KB
testcase_26 AC 110 ms
55,952 KB
testcase_27 AC 131 ms
56,200 KB
testcase_28 AC 129 ms
56,268 KB
testcase_29 AC 114 ms
56,036 KB
testcase_30 AC 116 ms
55,580 KB
testcase_31 AC 117 ms
55,972 KB
testcase_32 AC 112 ms
55,896 KB
testcase_33 AC 109 ms
56,264 KB
testcase_34 AC 109 ms
56,332 KB
testcase_35 AC 112 ms
56,176 KB
testcase_36 AC 113 ms
55,812 KB
testcase_37 AC 136 ms
56,476 KB
testcase_38 AC 109 ms
56,336 KB
testcase_39 AC 127 ms
56,268 KB
testcase_40 AC 110 ms
56,172 KB
testcase_41 AC 109 ms
55,948 KB
testcase_42 AC 110 ms
56,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int[] prices;
    static int[] dp;
    static int n;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		prices = new int[n];
		for (int i = 0; i < n; i++) {
		    prices[i] = sc.nextInt();
		}
		dp = new int[1 << n];
		Arrays.fill(dp, -1);
		dp[0] = 0;
		System.out.println(dfw((1 << n) - 1));
	}
	
	static int dfw(int mask) {
	    if (dp[mask] >= 0) {
	        return dp[mask];
	    }
	    dp[mask] = Integer.MAX_VALUE;
	    int total = 0;
	    for (int i = 0; i < n; i++) {
	        if ((mask & (1 <<i)) == 0) {
	            continue;
	        }
	        total += prices[i];
	    }
	    for (int i = 0; i < n; i++) {
	        if ((mask & (1 <<i)) == 0) {
	            continue;
	        }
	        dp[mask] = Math.min(dp[mask], dfw(mask ^ (1 << i)) + Math.max(0, prices[i] - (total - prices[i]) % 1000));
	    }
	    return dp[mask];
	}
}
0