結果

問題 No.189 SUPER HAPPY DAY
ユーザー らーゆらーゆ
提出日時 2024-03-29 13:03:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 5,000 ms
コード長 978 bytes
コンパイル時間 936 ms
コンパイル使用メモリ 66,196 KB
実行使用メモリ 22,500 KB
最終ジャッジ日時 2024-03-29 13:03:37
合計ジャッジ時間 3,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
22,496 KB
testcase_01 AC 11 ms
22,496 KB
testcase_02 AC 8 ms
22,496 KB
testcase_03 AC 13 ms
22,496 KB
testcase_04 AC 11 ms
22,496 KB
testcase_05 AC 15 ms
22,496 KB
testcase_06 AC 11 ms
22,496 KB
testcase_07 AC 12 ms
22,496 KB
testcase_08 AC 12 ms
22,496 KB
testcase_09 AC 12 ms
22,496 KB
testcase_10 AC 12 ms
22,496 KB
testcase_11 AC 12 ms
22,496 KB
testcase_12 AC 12 ms
22,496 KB
testcase_13 AC 76 ms
22,500 KB
testcase_14 AC 94 ms
22,500 KB
testcase_15 AC 81 ms
22,500 KB
testcase_16 AC 83 ms
22,500 KB
testcase_17 AC 95 ms
22,500 KB
testcase_18 AC 77 ms
22,500 KB
testcase_19 AC 111 ms
22,500 KB
testcase_20 AC 47 ms
22,496 KB
testcase_21 AC 56 ms
22,500 KB
testcase_22 AC 21 ms
22,496 KB
testcase_23 AC 63 ms
22,500 KB
testcase_24 AC 60 ms
22,500 KB
testcase_25 AC 110 ms
22,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*<アイデア> dp[桁数][未満フラグ][数字和]
dp[i+1][j || d<D][k+d]+=dp[i][j][k]*/
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
typedef long long ll;
ll mod = 1000000009;
ll dp[2][300][2][2010];
void make_dp(const string &S, int a) {
	dp[a][0][0][0] = 1;
	for (int i = 0; i < S.length(); i++) {
		int D = S[i]-'0';
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2000; k++) {
				for (int d = 0; d <= (j ? 9 : D); d++) {
					dp[a][i + 1][j || (d < D)][k + d] += dp[a][i][j][k];
					dp[a][i + 1][j || (d < D)][k + d] %= mod;
				}
			}
		}
	}
}
int main() {
	ll ans = 0;
	string S, T;
	cin >> S >> T;
	memset(dp, 0, sizeof(dp));
	make_dp(S, 0);
	make_dp(T, 1);
	for (int k = 0; k < 2000; k++) {
		ll p = dp[0][S.length()][0][k] + dp[0][S.length()][1][k];
		ll q = dp[1][T.length()][0][k] + dp[1][T.length()][1][k];
		ans += p * q;
		ans %= mod;
	}
	cout << (ans + mod - 1) % mod << endl;
}
0