結果
問題 | No.42 貯金箱の溜息 |
ユーザー |
![]() |
提出日時 | 2020-04-19 14:10:27 |
言語 | C++17 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 4,578 ms / 5,000 ms |
コード長 | 994 bytes |
コンパイル時間 | 1,776 ms |
使用メモリ | 4,904 KB |
最終ジャッジ日時 | 2022-11-28 10:54:51 |
合計ジャッジ時間 | 21,026 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 4,553 ms
4,904 KB |
testcase_01 | AC | 4,550 ms
4,904 KB |
testcase_02 | AC | 4,578 ms
4,904 KB |
ソースコード
#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(); }