結果

問題 No.42 貯金箱の溜息
ユーザー 紙ぺーぱー紙ぺーぱー
提出日時 2016-05-31 21:40:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3,704 ms / 5,000 ms
コード長 563 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 165,232 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-29 15:33:26
合計ジャッジ時間 10,836 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int MOD=1000000009;
const int SZ=1350;
const int a[]{1,5,10,50,100,500};
int dp[SZ]{};
int ndp[SZ]{};
int main(){
  int t;
  cin>>t;
  while(t--){
    long long m;
    cin>>m;
    for(int i=0;i<SZ;i++)dp[i]=ndp[i]=0;
    dp[0]=1;
    while(m){
      for(int i=0;i<SZ;i++){ndp[i]=dp[i];dp[i]=0;}
      for(int i=0;i<6;i++)
        for(int j=SZ-1;j>=a[i];j--)
         if((ndp[j]+=ndp[j-a[i]])>=MOD)ndp[j]-=MOD;
      for(int i=m&1;i<SZ;i+=2)
        dp[i/2]=ndp[i];
      m/=2;
    }
    cout<<dp[0]<<endl;
  }
}
0