結果

問題 No.137 貯金箱の焦り
ユーザー MahdiSiyamMahdiSiyam
提出日時 2023-04-30 19:44:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,118 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 167,252 KB
実行使用メモリ 6,016 KB
最終ジャッジ日時 2024-04-29 23:58:38
合計ジャッジ時間 10,929 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
6,016 KB
testcase_01 AC 6 ms
6,016 KB
testcase_02 AC 9 ms
6,016 KB
testcase_03 AC 4 ms
6,016 KB
testcase_04 AC 904 ms
5,888 KB
testcase_05 AC 267 ms
5,888 KB
testcase_06 AC 282 ms
5,888 KB
testcase_07 AC 127 ms
6,016 KB
testcase_08 AC 158 ms
6,016 KB
testcase_09 AC 353 ms
5,888 KB
testcase_10 AC 167 ms
6,016 KB
testcase_11 AC 4 ms
6,016 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 129 ms
6,016 KB
testcase_21 RE -
testcase_22 AC 1,978 ms
5,888 KB
testcase_23 AC 2,067 ms
6,016 KB
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#ifdef LOKAL
#include "DEBUG_TEMPLATE.h"
#else
#define HERE
#define debug(args...)
#endif
typedef pair<int,int> pii;
#define ALL(x) x.begin(),x.end()

const int N = 5000 +15;
const ll oo = 1234567891LL;

int n;
ll m;
ll pos[N];
ll save[65][N];
int sum = 0;



ll dp(int i,int c)
{
	if(i==60)
		return c==0;
	ll &ret=save[i][c];
	if(ret!=-1) return ret;
	ret=0;
	for(int j=0;j<=sum;j++)
	{
		int now = c+j;
		if(((now >>0)&1) == ((m>>i)&1))
		{
			ll x = dp(i+1,now/2);
			ret = (ret + pos[j] * x % oo)%oo;
		}
	}
	return ret;
}

void solve()
{
	debug(oo*oo);
	cin>>n>>m;
	pos[0]=1;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		sum+=a;
		for(int j=sum;j>=a;j--)
			pos[j]=(pos[j]+pos[j-a])%oo;
	}
	// for(int i=0;i<=m;i++)
	// 	debug(i,pos[i]);
	memset(save,-1,sizeof(save));
	cout<<dp(0,0)<<endl;
}
/*

*/

int32_t main()
{
#ifndef LOKAL
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int T=1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}

		   	  	 			 	  			    		  	 	
0