結果

問題 No.137 貯金箱の焦り
ユーザー the-tool-erthe-tool-er
提出日時 2023-05-03 11:14:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 266 ms / 5,000 ms
コード長 1,789 bytes
コンパイル時間 1,708 ms
コンパイル使用メモリ 168,108 KB
実行使用メモリ 29,512 KB
最終ジャッジ日時 2024-05-01 12:33:23
合計ジャッジ時間 4,053 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,816 KB
testcase_01 AC 3 ms
6,816 KB
testcase_02 AC 3 ms
6,812 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 12 ms
7,876 KB
testcase_05 AC 7 ms
6,984 KB
testcase_06 AC 8 ms
6,940 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 6 ms
6,940 KB
testcase_09 AC 8 ms
7,112 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 266 ms
29,512 KB
testcase_13 AC 155 ms
19,652 KB
testcase_14 AC 139 ms
18,252 KB
testcase_15 AC 122 ms
18,120 KB
testcase_16 AC 115 ms
17,224 KB
testcase_17 AC 43 ms
12,228 KB
testcase_18 AC 110 ms
17,224 KB
testcase_19 AC 132 ms
17,608 KB
testcase_20 AC 4 ms
6,944 KB
testcase_21 AC 64 ms
14,020 KB
testcase_22 AC 13 ms
8,904 KB
testcase_23 AC 13 ms
9,036 KB
testcase_24 AC 35 ms
11,468 KB
testcase_25 AC 81 ms
14,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Problem: No.137 貯金箱の焦り
// Contest: yukicoder
// URL: https://yukicoder.me/problems/no/137
// Memory Limit: 512 MB
// Time Limit: 5000 ms

/*
hxz还是爬的好
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(ll i=a;i<=b;i++)
#define wt int tt=d;while(tt--)
#define py puts("Yes")
#define pn puts("No")
#define pritnf printf
#define edfl endl
#define fe(i,e) for(int i=0;i<e.size();i++)
#define vi vector<ll>
inline ll rd() {
	ll x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
namespace binom{
	const ll Lim=300010,mod=998244353;
	ll jc[Lim],inv[Lim],inc[Lim];
	void pre(){
		jc[0]=jc[1]=inc[0]=inc[1]=inv[0]=inv[1]=1;
		f(i,2,Lim-1)jc[i]=jc[i-1]*i%mod,inv[i]=(mod-mod/i)*inv[mod%i]%mod,
		inc[i]=inc[i-1]*inv[i]%mod;
	}ll C(ll n,ll m){if(n<0||m<0||n<m)return 0;return jc[n]*inc[m]%mod*inc[n-m]%mod;}
}
// using namespace binom;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
#define d rd()
#define pb push_back
const ll N=300010;
struct edge{ll v,w,nx;}e[N<<1];
ll hd[N],cnt;
void add(ll u,ll v,ll w){e[++cnt]=(edge){v,w,hd[u]};hd[u]=cnt;}
ll qp(ll a,ll b,ll p){
	ll ans=1;while(b){
		if(b&1)ans=ans*a%p;
		a=a*a%p;b>>=1;
	}return ans;
}ll n,m;
ll dp[110][50010];//前 i-1 位与m相同,第i位及以上的值=j 的方案数
ll a[510],s;
const ll mod=1234567891;
int main(){
	n=d,m=d;
	f(i,1,n)a[i]=d,s+=a[i];dp[0][0]=1;
	f(i,1,n)for(int j=2*s-a[i];j>=0;j--)dp[0][j+a[i]]=(dp[0][j+a[i]]+dp[0][j])%mod;
	f(bit,1,63){
		f(i,0,2*s)if((i&1)==((m>>(bit-1))&1))dp[bit][i>>1]=(dp[bit][i>>1]+dp[bit-1][i])%mod;
		f(i,1,n)for(int j=2*s-a[i];j>=0;j--)dp[bit][j+a[i]]=(dp[bit][j+a[i]]+dp[bit][j])%mod;
	}cout<<dp[63][0];
	return 0;
}
/*
wy还是爬的好
*/
0