結果

問題 No.189 SUPER HAPPY DAY
ユーザー mayoko_mayoko_
提出日時 2015-04-22 20:30:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 1,482 bytes
コンパイル時間 2,028 ms
コンパイル使用メモリ 145,544 KB
実行使用メモリ 15,960 KB
最終ジャッジ日時 2023-09-18 08:21:09
合計ジャッジ時間 3,211 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,416 KB
testcase_01 AC 3 ms
5,592 KB
testcase_02 AC 2 ms
5,416 KB
testcase_03 AC 3 ms
5,560 KB
testcase_04 AC 3 ms
5,656 KB
testcase_05 AC 3 ms
5,620 KB
testcase_06 AC 3 ms
5,588 KB
testcase_07 AC 3 ms
5,588 KB
testcase_08 AC 3 ms
5,792 KB
testcase_09 AC 3 ms
5,624 KB
testcase_10 AC 3 ms
5,548 KB
testcase_11 AC 3 ms
5,620 KB
testcase_12 AC 3 ms
5,568 KB
testcase_13 AC 18 ms
10,128 KB
testcase_14 AC 23 ms
11,644 KB
testcase_15 AC 19 ms
10,536 KB
testcase_16 AC 19 ms
10,796 KB
testcase_17 AC 22 ms
11,876 KB
testcase_18 AC 18 ms
10,376 KB
testcase_19 AC 26 ms
13,264 KB
testcase_20 AC 12 ms
8,888 KB
testcase_21 AC 13 ms
8,348 KB
testcase_22 AC 4 ms
5,760 KB
testcase_23 AC 15 ms
10,480 KB
testcase_24 AC 17 ms
9,712 KB
testcase_25 AC 31 ms
15,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;

ll dp[2][222][2000][2];
const ll MOD = 1e9+9;

void makeDP(const string& s, int a) {
    int n = s.size();
    dp[a][0][0][1] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2000; j++) {
            for (int k = 0; k < 2; k++) {
                if (k == 0) {
                    for (int b = 0; b < 10; b++) {
                        dp[a][i+1][j+b][0] += dp[a][i][j][0];
                        dp[a][i+1][j+b][0] %= MOD;
                    }
                } else {
                    int tmp = s[i] - '0';
                    for (int b = 0; b < tmp; b++) {
                        dp[a][i+1][j+b][0] += dp[a][i][j][1];
                        dp[a][i+1][j+b][0] %= MOD;
                    }
                    dp[a][i+1][j+tmp][1] += dp[a][i][j][1];
                    dp[a][i+1][j+tmp][1] %= MOD;
                }
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    makeDP(s, 0); makeDP(t, 1);
    int n = s.size(), m = t.size();
    ll ans = 0;
    for (int i = 0; i < 2000; i++) {
        ll p = dp[0][n][i][0]+dp[0][n][i][1];
        ll q = dp[1][m][i][0]+dp[1][m][i][1];
        ans += p*q;
        ans %= MOD;
    }
    cout << (ans+MOD-1)%MOD << endl;
    return 0;
}
0