結果
問題 | No.286 Modulo Discount Store |
ユーザー |
|
提出日時 | 2015-10-09 23:37:25 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 169 ms / 2,000 ms |
コード長 | 973 bytes |
コンパイル時間 | 5,829 ms |
コンパイル使用メモリ | 77,316 KB |
実行使用メモリ | 41,656 KB |
最終ジャッジ日時 | 2024-07-20 04:43:11 |
合計ジャッジ時間 | 13,107 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
import java.util.Arrays;import java.util.Scanner;public class Main_yukicoder286 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);n = sc.nextInt();m = new int[n];for (int i = 0; i < n; i++) {m[i] = sc.nextInt();}int[] dp = new int[0x1 << n];dp[0] = 0;for (int i = 0; i < 0x1 << n; i++) {for (int j = 0; j < n; j++) {if ((i & (0x1 << j)) != 0) {continue;}dp[i | (0x1 << j)] = Math.max(dp[i | (0x1 << j)], dp[i] + Math.min(sum(i) % 1000, m[j]));}}System.out.println(sum((0x1 << n) - 1) - dp[(0x1 << n) - 1]);sc.close();}private static int n;private static int[] m;private static int sum(int i) {int ret = 0;for (int j = 0; j < n; j++) {if ((i & (0x1 << j)) != 0) {ret += m[j];}}return ret;}}