結果

問題 No.42 貯金箱の溜息
ユーザー HIR180HIR180
提出日時 2020-04-19 14:10:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3,873 ms / 5,000 ms
コード長 994 bytes
コンパイル時間 2,282 ms
コンパイル使用メモリ 196,300 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 12:09:23
合計ジャッジ時間 18,333 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,873 ms
6,816 KB
testcase_01 AC 3,851 ms
6,816 KB
testcase_02 AC 3,855 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()
#define pb push_back
typedef pair<int,int> P;
#define fi first
#define sc second
#define mp make_pair

typedef unsigned int ui;
const ui mod = 1000000009;
ui dp[64][705], tmp[1405], n = 6, a[6] = {1, 5, 10, 50, 100, 500};
long long m;

inline void add(ui &a, ui b) { a += b; if(a >= mod) a -= mod; }
void solve(){
	cin >> m;
	memset(dp, 0, sizeof(dp));
	memset(tmp, 0, sizeof(tmp));
	dp[0][0] = 1;
	int c = 0;
	rep(i, 60){
	    memset(tmp, 0, sizeof(tmp));
	    memcpy(tmp, *(dp+i), sizeof(*(dp+i)));
	    rep(j, n){
	        for(int k=c;k>=0;k--) add(tmp[k+a[j]], tmp[k]);
	        c += a[j];
	    }
		int f = ((m>>i)&1);
		rep(j, c+1){
		    if(f != (j&1)) continue;
			add(dp[i+1][j/2], tmp[j]);
		}
		c /= 2;
	}
	cout << dp[60][0] << '\n';
}

int main(){
    ios::sync_with_stdio(0);
    int t; cin >> t;
    while(t--) solve();
}
0