結果

問題 No.189 SUPER HAPPY DAY
ユーザー chakkuchakku
提出日時 2015-06-20 13:09:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 1,627 bytes
コンパイル時間 520 ms
コンパイル使用メモリ 67,396 KB
実行使用メモリ 16,200 KB
最終ジャッジ日時 2023-09-21 22:01:11
合計ジャッジ時間 2,410 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,464 KB
testcase_01 AC 3 ms
5,664 KB
testcase_02 AC 2 ms
5,464 KB
testcase_03 AC 3 ms
5,564 KB
testcase_04 AC 3 ms
5,560 KB
testcase_05 AC 4 ms
5,760 KB
testcase_06 AC 4 ms
5,572 KB
testcase_07 AC 3 ms
5,580 KB
testcase_08 AC 4 ms
5,548 KB
testcase_09 AC 4 ms
5,640 KB
testcase_10 AC 4 ms
5,596 KB
testcase_11 AC 4 ms
5,584 KB
testcase_12 AC 4 ms
5,612 KB
testcase_13 AC 28 ms
9,828 KB
testcase_14 AC 37 ms
11,304 KB
testcase_15 AC 32 ms
11,248 KB
testcase_16 AC 32 ms
11,552 KB
testcase_17 AC 36 ms
11,504 KB
testcase_18 AC 30 ms
10,796 KB
testcase_19 AC 44 ms
12,928 KB
testcase_20 AC 16 ms
7,240 KB
testcase_21 AC 21 ms
8,320 KB
testcase_22 AC 7 ms
6,184 KB
testcase_23 AC 25 ms
11,576 KB
testcase_24 AC 23 ms
10,160 KB
testcase_25 AC 46 ms
16,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define MOD 1000000009
typedef long long LL;

LL dpM[210][2][2000];
LL dpD[210][2][2000];

int main(){
	string m, d;
	cin >> m >> d;
	//dp[桁数][未満確定][合計値]=ケース数
	dpM[0][0][0] = 1;
	dpD[0][0][0] = 1;
	LL ml = m.length();
	LL dl = d.length();
	for (LL i = 0; i < ml; i++){
		LL numM = m[i]-'0';
		for (LL j = 0; j < 2; j++){
			for (LL k = 0; k < 2000; k++){
				for (LL d = 0; d <= (j ? 9 : numM); d++){
					dpM[i + 1][j || d < numM][k + d] = (dpM[i + 1][j || d < numM][k + d] + dpM[i][j][k]) % MOD;
//					cout << i << " " << j << " " << k << " :: ";
//					cout << "dpm[" << i + 1 << "][" << (j || d < num) << "][" << k + d << "] += dpm[" << i << "][" << j << "][" << k << "]" << endl;
				}
			}
		}
	}
	for (LL i = 0; i < dl; i++){
		LL numD = d[i] - '0';
		for (LL j = 0; j < 2; j++){
			for (LL k = 0; k < 2000; k++){
				for (LL d = 0; d <= (j ? 9 : numD); d++){
					dpD[i + 1][j || d < numD][k + d] = (dpD[i + 1][j || d < numD][k + d] + dpD[i][j][k]) % MOD;
				}
			}
		}
	}

	//for (int i = 0; i < 10; i++){
	//	cout << dpM[ml][0][i] + dpM[ml][1][i] << ":::" << dpD[ml][0][i] + dpD[ml][1][i] << endl;
	//}

	LL ans = 0;
	LL Mans[2000] = { 0 };
	LL Dans[2000] = { 0 };
	for (LL i = 1; i < 2000; i++){
		Mans[i] += dpM[ml][0][i] + dpM[ml][1][i];
		Dans[i] += dpD[dl][0][i] + dpD[dl][1][i];
		Mans[i] %= MOD;
		Dans[i] %= MOD;
	}

	for (LL i = 0; i < 2000; i++){
		ans += Mans[i] * Dans[i];
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}
0