結果

問題 No.42 貯金箱の溜息
ユーザー gaokai2050gaokai2050
提出日時 2022-11-10 13:05:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 5,000 ms
コード長 741 bytes
コンパイル時間 1,395 ms
コンパイル使用メモリ 164,712 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 21:44:35
合計ジャッジ時間 1,975 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
4,376 KB
testcase_01 AC 37 ms
4,376 KB
testcase_02 AC 37 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000009;
inline void add(ll &x,ll y) { x+=y; if (x>=mod) x-=mod; }
ll dp[100501];
ll rev(ll a) {
	ll r=1, n=mod-2;
	while(n) {
		if (n&1) r=r*a%mod;
		a=a*a%mod,n>>=1;
	}
	return r;
}
ll solve(ll x) {
	ll q=x/500,r=x%500,ret=0;	
	for (int i=0;i<=6;++i) {
		ll a=1,b=1;
		for (int j=0;j<=6;++j)
			if (i!=j) a=a*(mod-(q-j)%mod)%mod;
		for (int j=0;j<=6;++j)
			if (i!=j) b=b*(mod-(i-j))%mod;
		add(ret,dp[r+i*500]*a%mod*rev(b));
	}	
	return ret%mod;
}
int main() {
	int a[10]={0,1,5,10,50,100,500};
	dp[0]=1;
	for (int i=1;i<=6;++i)
		for (int j=a[i];j<=100000;++j)
			add(dp[j],dp[j-a[i]]);
	int T; ll x;
	cin>>T;
	while (T--) cin>>x,cout<<solve(x)<<endl;
}
0