結果

問題 No.189 SUPER HAPPY DAY
ユーザー ty70ty70
提出日時 2016-10-18 03:29:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 1,325 bytes
コンパイル時間 1,120 ms
コンパイル使用メモリ 159,720 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2024-05-02 02:18:59
合計ジャッジ時間 2,578 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
15,872 KB
testcase_01 AC 10 ms
16,000 KB
testcase_02 AC 10 ms
16,000 KB
testcase_03 AC 11 ms
16,000 KB
testcase_04 AC 11 ms
15,872 KB
testcase_05 AC 10 ms
16,000 KB
testcase_06 AC 10 ms
16,000 KB
testcase_07 AC 11 ms
16,000 KB
testcase_08 AC 10 ms
15,872 KB
testcase_09 AC 11 ms
16,000 KB
testcase_10 AC 11 ms
16,000 KB
testcase_11 AC 11 ms
15,872 KB
testcase_12 AC 11 ms
16,000 KB
testcase_13 AC 28 ms
16,000 KB
testcase_14 AC 34 ms
16,000 KB
testcase_15 AC 30 ms
16,000 KB
testcase_16 AC 31 ms
16,000 KB
testcase_17 AC 36 ms
16,000 KB
testcase_18 AC 32 ms
16,000 KB
testcase_19 AC 40 ms
16,000 KB
testcase_20 AC 21 ms
16,000 KB
testcase_21 AC 22 ms
15,872 KB
testcase_22 AC 13 ms
16,000 KB
testcase_23 AC 23 ms
16,000 KB
testcase_24 AC 23 ms
16,000 KB
testcase_25 AC 38 ms
16,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll MOD = (ll)1e9 + 9LL;

ll dp[2][202][2][2000];// dp[0:Mの数字 1:Dの数字][i桁目][(M,D)未満であることが確定している 0: していない 1: している][各桁の和]

ll solve(string M, string D){
	memset(dp, 0LL, sizeof(dp));

	int n1 = M.length();
	int n2 = D.length();

	dp[0][0][0][0] = 1LL;
	dp[1][0][0][0] = 1LL;
	for (int md = 0; md < 2; ++md){ // md = 0 -> M md = 1 -> D
		for (int i = 0; i < (md == 0 ? n1 : n2); ++i){
			int D1 = (int)(md == 0 ? (M[i] - '0') : (D[i] - '0'));
			for (int j = 0; j < 2; ++j){
				for (int k = 0; k < 2000; ++k){
					for (int d = 0; d < (j ? 10 : D1 + 1); ++d){
						ll & ans = dp[md][i + 1][j || d < D1][k + d];
						ans = (ans + dp[md][i][j][k]) % MOD;
					} // end for
				} // end for
			} // end for
		} // end for
	} // end for

	ll res = 0LL;
	for (int k = 1; k < 2000; ++k){
		res = (res + (((dp[0][n1][0][k] + dp[0][n1][1][k]) % MOD) * ((dp[1][n2][0][k] + dp[1][n2][1][k])% MOD)) % MOD) % MOD;
	} // end for

	return res;
} 

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string M, D; cin >> M >> D;

	ll res = solve(M, D);

	cout << res << endl;

	return 0;
}
0