結果

問題 No.137 貯金箱の焦り
ユーザー 👑 hos.lyrichos.lyric
提出日時 2015-01-05 05:33:14
言語 D
(dmd 2.099.1)
結果
AC  
実行時間 1,002 ms / 5,000 ms
コード長 733 bytes
コンパイル時間 775 ms
使用メモリ 3,572 KB
最終ジャッジ日時 2023-01-28 19:34:10
合計ジャッジ時間 7,056 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 3 ms
3,332 KB
testcase_01 AC 2 ms
3,244 KB
testcase_02 AC 2 ms
3,188 KB
testcase_03 AC 1 ms
3,348 KB
testcase_04 AC 27 ms
3,352 KB
testcase_05 AC 14 ms
3,336 KB
testcase_06 AC 15 ms
3,360 KB
testcase_07 AC 7 ms
3,344 KB
testcase_08 AC 8 ms
3,344 KB
testcase_09 AC 17 ms
3,324 KB
testcase_10 AC 7 ms
3,304 KB
testcase_11 AC 2 ms
3,304 KB
testcase_12 AC 1,002 ms
3,572 KB
testcase_13 AC 545 ms
3,304 KB
testcase_14 AC 479 ms
3,356 KB
testcase_15 AC 412 ms
3,348 KB
testcase_16 AC 390 ms
3,228 KB
testcase_17 AC 130 ms
3,284 KB
testcase_18 AC 375 ms
3,344 KB
testcase_19 AC 438 ms
3,324 KB
testcase_20 AC 2 ms
3,328 KB
testcase_21 AC 205 ms
3,300 KB
testcase_22 AC 24 ms
3,280 KB
testcase_23 AC 23 ms
3,364 KB
testcase_24 AC 101 ms
3,248 KB
testcase_25 AC 264 ms
3,364 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