結果

問題 No.137 貯金箱の焦り
ユーザー ぴろずぴろず
提出日時 2015-02-24 00:31:58
言語 Java19
(openjdk 21)
結果
AC  
実行時間 1,115 ms / 5,000 ms
コード長 756 bytes
コンパイル時間 1,893 ms
コンパイル使用メモリ 73,896 KB
実行使用メモリ 56,720 KB
最終ジャッジ日時 2023-08-07 18:12:11
合計ジャッジ時間 12,906 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
56,140 KB
testcase_01 AC 189 ms
56,112 KB
testcase_02 AC 186 ms
56,272 KB
testcase_03 AC 124 ms
56,004 KB
testcase_04 AC 198 ms
55,984 KB
testcase_05 AC 165 ms
56,068 KB
testcase_06 AC 193 ms
55,768 KB
testcase_07 AC 177 ms
56,224 KB
testcase_08 AC 178 ms
56,388 KB
testcase_09 AC 196 ms
56,252 KB
testcase_10 AC 190 ms
55,992 KB
testcase_11 AC 185 ms
55,936 KB
testcase_12 AC 1,115 ms
56,720 KB
testcase_13 AC 241 ms
56,132 KB
testcase_14 AC 829 ms
56,424 KB
testcase_15 AC 744 ms
56,344 KB
testcase_16 AC 741 ms
56,264 KB
testcase_17 AC 448 ms
56,440 KB
testcase_18 AC 508 ms
55,920 KB
testcase_19 AC 814 ms
56,340 KB
testcase_20 AC 205 ms
56,196 KB
testcase_21 AC 543 ms
56,096 KB
testcase_22 AC 253 ms
56,500 KB
testcase_23 AC 241 ms
56,524 KB
testcase_24 AC 395 ms
55,872 KB
testcase_25 AC 623 ms
56,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no137;

import java.util.Scanner;

public class Main {
	public static final int MAX = 50000;
	public static final long MOD = 1234567891;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long m = sc.nextLong();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		long[] dp = new long[MAX+1];
		dp[0] = 1;
		while(m > 0) {
			for(int i=0;i<n;i++) {
				for(int j=MAX;j>=a[i];j--) {
					dp[j] += dp[j-a[i]];
					if (dp[j] >= MOD) {
						dp[j] -= MOD;
					}
				}
			}
			for(int i=0;i<=MAX;i++) {
				int j = (int) (i * 2 + (m & 1));
				if (j <= MAX) {
					dp[i] = dp[j];
				}else{
					dp[i] = 0;
				}
			}
			m /= 2;
		}
		System.out.println(dp[0]);
	}

}
0