結果

問題 No.137 貯金箱の焦り
ユーザー ぴろずぴろず
提出日時 2015-02-24 00:14:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 939 ms / 5,000 ms
コード長 891 bytes
コンパイル時間 3,045 ms
コンパイル使用メモリ 76,576 KB
実行使用メモリ 42,336 KB
最終ジャッジ日時 2024-04-25 11:44:04
合計ジャッジ時間 13,916 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 141 ms
42,140 KB
testcase_01 AC 173 ms
41,812 KB
testcase_02 AC 207 ms
41,740 KB
testcase_03 AC 117 ms
40,568 KB
testcase_04 AC 211 ms
42,148 KB
testcase_05 AC 164 ms
42,156 KB
testcase_06 AC 210 ms
41,724 KB
testcase_07 AC 188 ms
42,004 KB
testcase_08 AC 179 ms
41,684 KB
testcase_09 AC 196 ms
41,528 KB
testcase_10 AC 186 ms
42,036 KB
testcase_11 AC 214 ms
42,200 KB
testcase_12 AC 927 ms
42,124 KB
testcase_13 AC 241 ms
41,508 KB
testcase_14 AC 939 ms
41,516 KB
testcase_15 AC 838 ms
41,468 KB
testcase_16 AC 834 ms
42,112 KB
testcase_17 AC 541 ms
42,008 KB
testcase_18 AC 793 ms
41,644 KB
testcase_19 AC 913 ms
41,588 KB
testcase_20 AC 211 ms
42,336 KB
testcase_21 AC 666 ms
41,860 KB
testcase_22 AC 311 ms
41,928 KB
testcase_23 AC 266 ms
41,400 KB
testcase_24 AC 494 ms
42,292 KB
testcase_25 AC 761 ms
41,728 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[2][MAX+1];
		int now = 1;
		int bef = 0;
		dp[bef][0] = 1;
		while(m > 0) {
			for(int i=0;i<n;i++) {
				for(int j=0;j<=MAX;j++) {
					dp[now][j] = dp[bef][j];
					if (a[i] <= j) {
						dp[now][j] += dp[bef][j-a[i]];
					}
					dp[now][j] %= MOD;
				}
				now = 1 - now;
				bef = 1 - bef;
			}
			for(int i=0;i<=MAX;i++) {
				int j = (int) (i * 2 + m % 2);
				if (j <= MAX) {
					dp[bef][i] = dp[bef][j];
				}else{
					dp[bef][i] = 0;
				}
			}
			m /= 2;
		}
		System.out.println(dp[bef][0]);
	}

}
0