結果

問題 No.189 SUPER HAPPY DAY
ユーザー btk
提出日時 2015-04-22 01:32:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 1,307 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 85,092 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-07-04 23:43:02
合計ジャッジ時間 1,849 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<fstream>
#include<sstream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<utility>
#include<complex>

using namespace std;
#define LL long long
const LL MOD = (LL)1e9 + 9;
LL nine[300][2000];
string M, D;
void dfs(int n,LL res[],string &s){
	s[n] -= '0';
	for (int i = 0; i < 1991; i++)
		for (int j = 0; j <(int)s[n] ; j++)
			res[i + j] = (res[i + j] + nine[s.size() - n - 1][i]) % MOD;
	
	LL left[2000] = { 0 };
	if (n+1 < (int)s.size()){
		dfs(n + 1, left, s);
		for (int i = 0; i < 1991; i++)
			res[i + s[n]] = (res[i + s[n]] + left[i]) % MOD;
	}
	else res[s[n]] = (res[s[n]]+1)%MOD;

	
}

int main(void){

	for (int i = 0; i < 10; i++)
		nine[1][i] = 1;
	for (int i = 2; i <= 200; i++)
		for (int j = 0; j < 1991; j++)
			for (int k = 0; k < 10; k++)
				nine[i][j + k] = (nine[i][j + k]+ nine[i - 1][j])%MOD;
	nine[0][0] = 1;
	cin >> M >> D;
	LL res1[2000] = { 0 };
	LL res2[2000] = { 0 };
	LL ans = 0;
	dfs(0, res1, M);
	dfs(0, res2, D);
	for (int i = 1; i < 2000; i++)
		ans = (ans + res1[i] * res2[i]) % MOD;
//	reverse(M.begin(), M.end());
//	reverse(D.begin(), M.end());
	cout << ans << endl;
	return(0);
}
0