結果

問題 No.137 貯金箱の焦り
ユーザー ぴろずぴろず
提出日時 2015-02-24 00:31:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,187 ms / 5,000 ms
コード長 756 bytes
コンパイル時間 2,516 ms
コンパイル使用メモリ 77,436 KB
実行使用メモリ 42,168 KB
最終ジャッジ日時 2024-04-25 11:44:21
合計ジャッジ時間 13,759 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
42,076 KB
testcase_01 AC 179 ms
41,632 KB
testcase_02 AC 215 ms
41,704 KB
testcase_03 AC 138 ms
41,640 KB
testcase_04 AC 224 ms
41,812 KB
testcase_05 AC 188 ms
41,756 KB
testcase_06 AC 210 ms
41,700 KB
testcase_07 AC 216 ms
42,152 KB
testcase_08 AC 244 ms
41,496 KB
testcase_09 AC 212 ms
41,556 KB
testcase_10 AC 234 ms
41,352 KB
testcase_11 AC 199 ms
41,140 KB
testcase_12 AC 1,187 ms
41,772 KB
testcase_13 AC 260 ms
41,692 KB
testcase_14 AC 872 ms
41,364 KB
testcase_15 AC 791 ms
41,896 KB
testcase_16 AC 786 ms
41,820 KB
testcase_17 AC 474 ms
41,540 KB
testcase_18 AC 481 ms
41,872 KB
testcase_19 AC 859 ms
41,652 KB
testcase_20 AC 218 ms
41,820 KB
testcase_21 AC 579 ms
42,168 KB
testcase_22 AC 307 ms
41,288 KB
testcase_23 AC 242 ms
41,496 KB
testcase_24 AC 411 ms
41,756 KB
testcase_25 AC 667 ms
42,036 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