結果

問題 No.137 貯金箱の焦り
ユーザー rabimearabimea
提出日時 2023-01-27 05:20:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 152 ms / 5,000 ms
コード長 913 bytes
コンパイル時間 2,043 ms
コンパイル使用メモリ 200,164 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-10 02:08:40
合計ジャッジ時間 4,839 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,380 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 20 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 19 ms
4,380 KB
testcase_05 AC 8 ms
4,384 KB
testcase_06 AC 18 ms
4,380 KB
testcase_07 AC 14 ms
4,376 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 19 ms
4,376 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 11 ms
4,376 KB
testcase_12 AC 152 ms
4,376 KB
testcase_13 AC 22 ms
4,376 KB
testcase_14 AC 147 ms
4,380 KB
testcase_15 AC 130 ms
4,376 KB
testcase_16 AC 133 ms
4,376 KB
testcase_17 AC 81 ms
4,376 KB
testcase_18 AC 126 ms
4,376 KB
testcase_19 AC 147 ms
4,380 KB
testcase_20 AC 14 ms
4,376 KB
testcase_21 AC 99 ms
4,380 KB
testcase_22 AC 37 ms
4,380 KB
testcase_23 AC 33 ms
4,380 KB
testcase_24 AC 71 ms
4,380 KB
testcase_25 AC 116 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define pb push_back
using vi = vector <int>;
using ll = long long;
using pii = pair <int, int>;
//~ const ll mod = 998244353;
//~ const ll mod = 1e9 + 7;
const ll mod = 1234567891;
ll qpow(ll a, ll b, ll m = mod) { ll r = 1, t = a;
	for(; b; b /= 2) { if(b & 1) r = r * t % m; t = t * t % m; } return r; }

const int N = 55, M = 5e4 + 11;

int a[N];
ll f[M], g[M];

void upd(ll &a, ll b) {
	a += b;
	if(a >= mod) a -= mod;
}

int main() {
	ios :: sync_with_stdio(false);
	
	int n; ll m;
	cin >> n >> m;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	
	f[0] = 1;
	while(m) {
		for(int i = 1; i <= n; i ++)
			for(int j = M - 1; j >= a[i]; j --)
				upd(f[j], f[j - a[i]]);
		
		memset(g, 0, sizeof g);
		for(int i = 0; i < M; i ++)
			if((m + i) % 2 == 0)
				g[i / 2] = f[i];
		swap(f, g);
		m /= 2;
	}
	
	cout << f[0] << '\n';
}
0