結果

問題 No.137 貯金箱の焦り
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-01-05 05:33:14
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 992 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 662 ms
コンパイル使用メモリ 88,752 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 19:27:11
合計ジャッジ時間 6,349 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,372 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 27 ms
4,372 KB
testcase_05 AC 14 ms
4,368 KB
testcase_06 AC 14 ms
4,368 KB
testcase_07 AC 7 ms
4,368 KB
testcase_08 AC 8 ms
4,372 KB
testcase_09 AC 16 ms
4,372 KB
testcase_10 AC 7 ms
4,368 KB
testcase_11 AC 1 ms
4,368 KB
testcase_12 AC 992 ms
4,372 KB
testcase_13 AC 540 ms
4,372 KB
testcase_14 AC 475 ms
4,372 KB
testcase_15 AC 409 ms
4,372 KB
testcase_16 AC 386 ms
4,368 KB
testcase_17 AC 128 ms
4,368 KB
testcase_18 AC 373 ms
4,368 KB
testcase_19 AC 436 ms
4,368 KB
testcase_20 AC 2 ms
4,368 KB
testcase_21 AC 203 ms
4,368 KB
testcase_22 AC 24 ms
4,368 KB
testcase_23 AC 22 ms
4,372 KB
testcase_24 AC 99 ms
4,368 KB
testcase_25 AC 264 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.stdio, std.string;

immutable long MO = 1_234_567_891;

void add(ref long t, in long f) {
	if ((t += f) >= MO) {
		t -= MO;
	}
}

void main() {
	string[] tokens;
	tokens = readln.chomp.split(" ");
	const N = tokens[0].to!int;
	const M = tokens[1].to!long;
	tokens = readln.chomp.split(" ");
	auto A = new int[N];
	foreach (i; 0 .. N) {
		A[i] = tokens[i].to!int;
	}
	
	const ASum = A.reduce!((a, b) => a + b);
	auto dp = new long[ASum * 2];
	dp[0] = 1;
	foreach (j; 0 .. 64) {
		foreach (i; 0 .. N) {
			foreach_reverse (x; A[i] .. ASum * 2) {
				add(dp[x], dp[x - A[i]]);
			}
		}
		foreach (x; 0 .. ASum) {
			dp[x] = dp[x << 1 | ((M >> j) & 1)];
		}
		dp[ASum .. $] = 0;
	}
	writeln(dp[0]);
}
0