結果

問題 No.286 Modulo Discount Store
ユーザー 37zigen37zigen
提出日時 2016-04-02 15:39:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 174 ms / 2,000 ms
コード長 803 bytes
コンパイル時間 2,597 ms
コンパイル使用メモリ 77,308 KB
実行使用メモリ 54,636 KB
最終ジャッジ日時 2024-04-10 10:37:55
合計ジャッジ時間 10,093 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
54,252 KB
testcase_01 AC 136 ms
54,136 KB
testcase_02 AC 153 ms
54,272 KB
testcase_03 AC 138 ms
54,176 KB
testcase_04 AC 140 ms
54,636 KB
testcase_05 AC 135 ms
54,288 KB
testcase_06 AC 158 ms
54,492 KB
testcase_07 AC 133 ms
54,236 KB
testcase_08 AC 134 ms
53,956 KB
testcase_09 AC 136 ms
54,384 KB
testcase_10 AC 144 ms
53,972 KB
testcase_11 AC 135 ms
54,080 KB
testcase_12 AC 136 ms
54,164 KB
testcase_13 AC 153 ms
53,964 KB
testcase_14 AC 135 ms
54,000 KB
testcase_15 AC 136 ms
54,432 KB
testcase_16 AC 136 ms
54,136 KB
testcase_17 AC 174 ms
53,916 KB
testcase_18 AC 141 ms
54,064 KB
testcase_19 AC 137 ms
54,132 KB
testcase_20 AC 145 ms
54,320 KB
testcase_21 AC 140 ms
54,060 KB
testcase_22 AC 141 ms
54,060 KB
testcase_23 AC 158 ms
54,416 KB
testcase_24 AC 141 ms
54,212 KB
testcase_25 AC 145 ms
54,476 KB
testcase_26 AC 141 ms
54,136 KB
testcase_27 AC 146 ms
53,824 KB
testcase_28 AC 161 ms
54,456 KB
testcase_29 AC 140 ms
54,456 KB
testcase_30 AC 140 ms
54,312 KB
testcase_31 AC 146 ms
54,512 KB
testcase_32 AC 144 ms
54,064 KB
testcase_33 AC 142 ms
53,948 KB
testcase_34 AC 145 ms
54,036 KB
testcase_35 AC 144 ms
54,216 KB
testcase_36 AC 142 ms
53,864 KB
testcase_37 AC 148 ms
54,440 KB
testcase_38 AC 138 ms
54,072 KB
testcase_39 AC 160 ms
54,364 KB
testcase_40 AC 140 ms
53,920 KB
testcase_41 AC 145 ms
54,116 KB
testcase_42 AC 138 ms
53,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder286;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static int[] data;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		data=new int[n];
		for(int i=0;i<n;i++){
			data[i]=sc.nextInt();
		}
		int[] dp=new int[1<<n];
		Arrays.fill(dp, Integer.MAX_VALUE);
		dp[0]=0;
		for(int mask=0;mask<1<<n;mask++){
			for(int i=0;i<n;i++){
				if((mask&(1<<i))==0){
					int nextMask=mask|(1<<i);
					int buy=data[i]-Math.min(data[i], (totalMoney(mask)%1000));
					dp[nextMask]=Math.min(dp[nextMask], buy+dp[mask]);
				}
			}
		}
		System.out.println(dp[(1<<n)-1]);
	}
	static int totalMoney(int bit){
		int total=0;
		for(int i=0;bit>>i>0;i++){
			if(((1<<i)&bit)>0){
				total+=data[i];
			}
		}
		return total;
	}
}
0