結果

問題 No.137 貯金箱の焦り
ユーザー chocoruskchocorusk
提出日時 2018-12-11 10:01:59
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,116 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 100,184 KB
実行使用メモリ 29,760 KB
最終ジャッジ日時 2023-10-19 22:32:01
合計ジャッジ時間 8,429 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
25,536 KB
testcase_01 AC 21 ms
25,532 KB
testcase_02 AC 22 ms
25,532 KB
testcase_03 AC 21 ms
25,532 KB
testcase_04 AC 132 ms
25,540 KB
testcase_05 AC 122 ms
25,540 KB
testcase_06 AC 131 ms
25,540 KB
testcase_07 AC 56 ms
25,536 KB
testcase_08 AC 59 ms
25,536 KB
testcase_09 AC 155 ms
25,544 KB
testcase_10 AC 52 ms
25,536 KB
testcase_11 AC 20 ms
25,532 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1234567891;
int main()
{
	int n; ll m;
	cin>>n>>m;
	int a[50];
	for(int i=0; i<n; i++) cin>>a[i];
	ll dp0[51][25001]={};
	dp0[0][0]=1;
	for(int i=0; i<n; i++){
		for(int j=0; j<=25000; j++){
			dp0[i+1][j]+=dp0[i][j];
			if(j>=a[i]) dp0[i+1][j]+=dp0[i][j-a[i]];
			dp0[i+1][j]%=MOD;
		}
	}
	vector<int> ind[2];
	for(int k=0; k<=25000; k++){
		if(dp0[n][k]==0) continue;
		ind[k&1].push_back(k);
	}
	ll dp[61][25001]={};
	dp[0][0]=1;
	for(int i=0; i<60; i++){
		int par=((m&(1ll<<i))?1:0);
		for(int j=0; j<=25000; j++){
			if(dp[i][j]==0) continue;
			for(auto k:ind[(j+par)&1]){
				if(dp0[n][k]==0) continue;
				dp[i+1][(j+k)/2]+=(dp[i][j]*dp0[n][k]);
				dp[i+1][(j+k)/2]%=MOD;
			}
		}
	}
	cout<<dp[60][0]<<endl;
	return 0;
}
0