結果

問題 No.137 貯金箱の焦り
ユーザー 沙耶花沙耶花
提出日時 2021-10-28 06:41:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,353 ms / 5,000 ms
コード長 1,547 bytes
コンパイル時間 4,719 ms
コンパイル使用メモリ 257,980 KB
実行使用メモリ 7,288 KB
最終ジャッジ日時 2024-04-16 12:59:14
合計ジャッジ時間 64,384 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 229 ms
7,028 KB
testcase_01 AC 615 ms
7,160 KB
testcase_02 AC 3,327 ms
7,032 KB
testcase_03 AC 60 ms
7,160 KB
testcase_04 AC 1,114 ms
7,028 KB
testcase_05 AC 392 ms
7,160 KB
testcase_06 AC 1,056 ms
7,032 KB
testcase_07 AC 1,060 ms
7,164 KB
testcase_08 AC 1,112 ms
7,288 KB
testcase_09 AC 1,113 ms
7,160 KB
testcase_10 AC 1,056 ms
7,160 KB
testcase_11 AC 3,332 ms
7,032 KB
testcase_12 AC 3,335 ms
7,032 KB
testcase_13 AC 449 ms
7,156 KB
testcase_14 AC 3,284 ms
7,028 KB
testcase_15 AC 3,339 ms
7,160 KB
testcase_16 AC 3,341 ms
7,160 KB
testcase_17 AC 3,292 ms
7,036 KB
testcase_18 AC 3,290 ms
7,160 KB
testcase_19 AC 3,336 ms
7,044 KB
testcase_20 AC 3,111 ms
7,036 KB
testcase_21 AC 3,334 ms
7,164 KB
testcase_22 AC 3,332 ms
7,036 KB
testcase_23 AC 3,225 ms
7,152 KB
testcase_24 AC 3,186 ms
7,036 KB
testcase_25 AC 3,353 ms
7,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000000000000

template <class T>
vector<T> convolution_mint(vector<T> a,vector<T> b){
	vector<long long> a1(a.size()),a2(a.size()),b1(b.size()),b2(b.size());
	rep(i,a.size()){
		a1[i] = a[i].val()>>15;
		a2[i] = a[i].val()&((1<<15)-1);
	}
	rep(i,b.size()){
		b1[i] = b[i].val()>>15;
		b2[i] = b[i].val()&((1<<15)-1);
	}
	
	vector<long long> A = convolution_ll(a1,b1), C = convolution_ll(a2,b2);
	
	rep(i,a1.size())a1[i] += a2[i];
	rep(i,b1.size())b1[i] += b2[i];
	
	vector<long long> B = convolution_ll(a1,b1);
	
	rep(i,B.size()){
		B[i] -= A[i] + C[i];
	}
	
	
	vector<T> ret(A.size(),0);
	rep(i,A.size()){
		ret[i] += (long long)T(A[i]).val()<<30;
		ret[i] += (long long)T(B[i]).val()<<15;
		ret[i] += T(C[i]).val();
	}
	return ret;
}

int main(){
	
	mint::set_mod(1234567891);
	
	int n;
	cin>>n;
	
	long long m;
	cin>>m;
	
	vector<int> a(n);
	rep(i,n)cin>>a[i];
	
	vector<mint> dp(25005,0);
	dp[0] = 1;
	
	rep(i,n){
		vector<mint> ndp(25005,0);
		rep(j,dp.size()){
			if(dp[j]==0)continue;
			ndp[j] += dp[j];
			
			ndp[j+a[i]] += dp[j];
		}
		swap(dp,ndp);
	}
	
	vector<mint> ddp(25005,0);
	ddp[0] = 1;
	
	while(m!=0){
		vector<mint> ndp = convolution_mint(dp,ddp);
		vector<mint> temp(25005,0);
		rep(i,ndp.size()){
			if(i%2!=m%2)continue;
			temp[i>>1] = ndp[i];
		}
		swap(temp,ddp);
		m>>=1;
	}
	
	cout<<ddp[0].val()<<endl;
	
	return 0;
}
0