結果

問題 No.286 Modulo Discount Store
ユーザー ぴろずぴろず
提出日時 2015-10-09 22:27:10
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 705 bytes
コンパイル時間 2,861 ms
コンパイル使用メモリ 74,076 KB
実行使用メモリ 58,060 KB
最終ジャッジ日時 2023-09-27 08:23:46
合計ジャッジ時間 9,906 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,760 KB
testcase_01 AC 121 ms
55,976 KB
testcase_02 AC 133 ms
55,500 KB
testcase_03 AC 121 ms
55,788 KB
testcase_04 AC 121 ms
56,404 KB
testcase_05 AC 126 ms
56,068 KB
testcase_06 AC 143 ms
55,664 KB
testcase_07 AC 120 ms
55,792 KB
testcase_08 AC 122 ms
55,724 KB
testcase_09 AC 123 ms
55,880 KB
testcase_10 AC 140 ms
55,700 KB
testcase_11 AC 121 ms
55,648 KB
testcase_12 AC 122 ms
56,100 KB
testcase_13 AC 133 ms
55,716 KB
testcase_14 AC 120 ms
55,868 KB
testcase_15 AC 120 ms
56,164 KB
testcase_16 AC 119 ms
56,144 KB
testcase_17 AC 137 ms
58,060 KB
testcase_18 AC 139 ms
55,816 KB
testcase_19 AC 123 ms
55,724 KB
testcase_20 AC 122 ms
55,776 KB
testcase_21 AC 121 ms
55,968 KB
testcase_22 AC 121 ms
55,968 KB
testcase_23 AC 131 ms
55,696 KB
testcase_24 AC 120 ms
56,204 KB
testcase_25 AC 123 ms
56,000 KB
testcase_26 AC 121 ms
55,784 KB
testcase_27 AC 124 ms
55,728 KB
testcase_28 AC 140 ms
56,044 KB
testcase_29 AC 123 ms
55,848 KB
testcase_30 AC 120 ms
55,920 KB
testcase_31 AC 121 ms
56,048 KB
testcase_32 AC 121 ms
56,428 KB
testcase_33 AC 121 ms
55,984 KB
testcase_34 AC 122 ms
55,848 KB
testcase_35 AC 121 ms
55,864 KB
testcase_36 AC 119 ms
55,796 KB
testcase_37 AC 124 ms
55,924 KB
testcase_38 AC 120 ms
55,992 KB
testcase_39 AC 136 ms
56,024 KB
testcase_40 AC 120 ms
55,956 KB
testcase_41 AC 120 ms
55,920 KB
testcase_42 AC 120 ms
55,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no286;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		int[] dp = new int[1<<n];
		Arrays.fill(dp, 1<<29);
		dp[0] = 0;
		for(int i=0;i<1<<n;i++) {
			int discount = 0;
			for(int j=0;j<n;j++) {
				if ((i >> j & 1) == 1) {
					discount += a[j];
				}
			}
			discount %= 1000;
			for(int j=0;j<n;j++) {
				if ((i >> j & 1) == 0) {
					int to = i|(1<<j);
					dp[to] = Math.min(dp[to], dp[i] + Math.max(a[j] - discount , 0));
				}
			}
		}
		System.out.println(dp[(1<<n)-1]);

	}

}
0