結果

問題 No.137 貯金箱の焦り
ユーザー rabimea
提出日時 2023-01-27 05:20:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 913 bytes
コンパイル時間 1,969 ms
コンパイル使用メモリ 192,920 KB
最終ジャッジ日時 2025-02-10 07:21:40
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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