結果
| 問題 | No.286 Modulo Discount Store |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2020-10-07 09:52:24 |
| 言語 | Java (openjdk 26.0.2.1 + ac-library) |
| 結果 |
AC
不安定
|
| 実行時間 | 79 ms / 2,000 ms |
| + 603µs | |
| コード長 | 945 bytes |
| 記録 | |
| コンパイル時間 | 2,121 ms |
| コンパイル使用メモリ | 84,072 KB |
| 実行使用メモリ | 45,172 KB |
| 最終ジャッジ日時 | 2026-08-19 09:58:08 |
| 合計ジャッジ時間 | 6,393 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
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];
}
}
tenten