結果

問題 No.137 貯金箱の焦り
ユーザー Vi24EVi24E
提出日時 2023-09-08 22:06:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 179 ms / 5,000 ms
コード長 683 bytes
コンパイル時間 4,343 ms
コンパイル使用メモリ 264,012 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-08 22:07:00
合計ジャッジ時間 6,223 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 179 ms
4,384 KB
testcase_13 AC 16 ms
4,380 KB
testcase_14 AC 93 ms
4,376 KB
testcase_15 AC 81 ms
4,376 KB
testcase_16 AC 78 ms
4,376 KB
testcase_17 AC 27 ms
4,376 KB
testcase_18 AC 73 ms
4,500 KB
testcase_19 AC 88 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 42 ms
4,376 KB
testcase_22 AC 7 ms
4,376 KB
testcase_23 AC 6 ms
4,380 KB
testcase_24 AC 21 ms
4,380 KB
testcase_25 AC 53 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;

int main(){
	ll n, m, s = 0;
	cin >> n >> m;
	modint::set_mod(1234567891);
	vector<int> a(n);
	for (auto &x : a) cin >> x; 

	for (int i = 0; i < n; i++) s += a[i];
	vector<modint> pre(2 * s + 1), dp(2 * s + 1);

	pre[0] = 1;
	for (int i = 0; (1ll<<i) <= m; i++){
		dp = pre;
		pre = vector<modint>(2 * s + 1);
		for (int j = 0; j < n; j++){
			for (int k = 2 * s; k >= a[j]; k--){
				dp[k] += dp[k - a[j]];
			}
		}

		for (int j = 0; j <= 2 * s; j++){
			if ((bool)(m & 1ll<<i) == (bool)(j & 1)){
				pre[j / 2] = dp[j];
			}
		}
	}
	cout << pre[0].val() << endl;
}
0