結果

問題 No.42 貯金箱の溜息
ユーザー 沙耶花沙耶花
提出日時 2021-10-27 18:13:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 744 ms / 5,000 ms
コード長 990 bytes
コンパイル時間 4,721 ms
コンパイル使用メモリ 267,316 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-29 05:30:50
合計ジャッジ時間 6,869 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

vector<vector<mint>> a;

void solve(){
	long long M;
	cin>>M;
	
	vector<mint> dp(22,0);
	dp[0] = 1;
	int c = 0;
	while(M!=0){
		vector<mint> ndp(22,0);
		
		rep(i,22){
			if(dp[i]==0)continue;
			rep(j,a[c].size()){
				if((i+j)%10!=M%10)continue;
				ndp[(i+j)/10] += dp[i] * a[c][j];
			}
		}
		
		c = min(c+1,2);
		swap(dp,ndp);
		
		M/=10;
	}
	
	cout<<dp[0].val()<<endl;	
}

int main(){
	
	mint::set_mod(1000000009);
	a.resize(3);
	a[0].resize(55,0);
	rep(i,10){
		rep(j,10){
			a[0][i+j*5] ++;
		}
	}
	
	a[1].resize(109,0);
	rep(i,55){
		rep(j,55){
			a[1][i+j] += a[0][i] * a[0][j];
		}
	}
	
	//cout<<a[0][10].val()<<endl;
	
	a[2].resize(108 + 54 + 1,0);
	rep(i,109){
		rep(j,55){
			a[2][i+j] += a[0][j] * a[1][i];
		}
	}
	
	int _t;
	cin>>_t;
	
	rep(_,_t)solve();
	
	return 0;
}
0