結果

問題 No.189 SUPER HAPPY DAY
ユーザー pekempey
提出日時 2015-08-12 16:43:07
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 1,251 bytes
コンパイル時間 1,139 ms
コンパイル使用メモリ 161,504 KB
実行使用メモリ 16,332 KB
最終ジャッジ日時 2024-07-18 06:58:14
合計ジャッジ時間 2,445 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) for (int i = (a) - 1; i >= 0; i--)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;
const ll inf = 1e9;
const ll mod = 1e9 + 9;

ll dp1[205][2030][2]; // pos, sum, less
ll dp2[205][2030][2]; // pos, sum, less

void calc(ll dp[205][2030][2], string s) {
    dp[0][0][0] = 1;

    rep (i, s.length()) {
        rep (j, 2020) {
            rep (k, 2) {
                int ub;
                if (k) {
                    ub = 9;
                } else {
                    ub = s[i] - '0';
                }

                rep (l, ub + 1) {
                    (dp[i + 1][j + l][k || l < ub] += dp[i][j][k]) %= mod;
                }
            }
        }
    }
}

int main() {
    string M, D;
    cin >> M >> D;

    calc(dp1, M);
    calc(dp2, D);

    rep (j, 2020) {
        dp1[M.length()][j][0] += dp1[M.length()][j][1];
        dp2[D.length()][j][0] += dp2[D.length()][j][1];
    }

    ll ans = 0;

    rep2 (i, 1, 2020) {
        ans += dp1[M.length()][i][0] * dp2[D.length()][i][0];
        ans %= mod;
    }

    cout << ans << endl;
}
0