結果

問題 No.286 Modulo Discount Store
ユーザー uafr_csuafr_cs
提出日時 2015-10-11 23:59:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 74,400 KB
実行使用メモリ 56,272 KB
最終ジャッジ日時 2023-09-28 12:25:43
合計ジャッジ時間 9,679 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
56,072 KB
testcase_01 AC 129 ms
55,852 KB
testcase_02 AC 143 ms
55,936 KB
testcase_03 AC 128 ms
56,036 KB
testcase_04 AC 129 ms
56,272 KB
testcase_05 AC 129 ms
55,560 KB
testcase_06 AC 144 ms
55,608 KB
testcase_07 AC 128 ms
55,792 KB
testcase_08 AC 127 ms
54,016 KB
testcase_09 AC 128 ms
55,796 KB
testcase_10 AC 136 ms
55,784 KB
testcase_11 AC 129 ms
56,192 KB
testcase_12 AC 132 ms
55,460 KB
testcase_13 AC 142 ms
55,936 KB
testcase_14 AC 126 ms
53,996 KB
testcase_15 AC 128 ms
56,148 KB
testcase_16 AC 127 ms
55,592 KB
testcase_17 AC 158 ms
56,052 KB
testcase_18 AC 137 ms
56,132 KB
testcase_19 AC 129 ms
56,004 KB
testcase_20 AC 131 ms
55,712 KB
testcase_21 AC 129 ms
55,808 KB
testcase_22 AC 131 ms
55,816 KB
testcase_23 AC 144 ms
55,924 KB
testcase_24 AC 130 ms
55,984 KB
testcase_25 AC 132 ms
55,904 KB
testcase_26 AC 126 ms
56,148 KB
testcase_27 AC 131 ms
55,976 KB
testcase_28 AC 144 ms
55,876 KB
testcase_29 AC 130 ms
55,936 KB
testcase_30 AC 126 ms
55,896 KB
testcase_31 AC 128 ms
56,100 KB
testcase_32 AC 130 ms
55,904 KB
testcase_33 AC 129 ms
55,780 KB
testcase_34 AC 129 ms
56,132 KB
testcase_35 AC 130 ms
55,792 KB
testcase_36 AC 129 ms
55,868 KB
testcase_37 AC 129 ms
55,764 KB
testcase_38 AC 129 ms
56,188 KB
testcase_39 AC 146 ms
55,488 KB
testcase_40 AC 130 ms
55,812 KB
testcase_41 AC 130 ms
55,552 KB
testcase_42 AC 126 ms
55,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int MOD = 1000;
		
		int[] items = new int[N];
		for(int i = 0; i < N; i++){
			items[i] = sc.nextInt();
		}
		
		final int bit_size = 1 << N;
		int[] mods = new int[bit_size];
		for(int bit = 0; bit < bit_size; bit++){
			for(int not_buy = 0; not_buy < N; not_buy++){
				if((bit & (1 << not_buy)) == 0){
					mods[bit | (1 << not_buy)] = (mods[bit] + items[not_buy]) % MOD;
				}
			}
		}
		
		int[] DP = new int[bit_size];
		for(int i = 0; i < bit_size; i++){
			DP[i]= Integer.MAX_VALUE;
		}
		
		for(int i = 0; i < N; i++){
			DP[1 << i] = items[i];
		}
		
		for(int bit = 1; bit < bit_size; bit++){	
			for(int new_buy = 0; new_buy < N; new_buy++){
				if((bit & (1 << new_buy)) != 0){
					continue;
				}
				
				final int next_bit = bit | (1 << new_buy);
				DP[next_bit] = Math.min(DP[next_bit], DP[bit] + items[new_buy] - Math.min(items[new_buy], mods[bit]));
			}
		}
		
		System.out.println(DP[bit_size - 1]);
	}

}
0