結果

問題 No.189 SUPER HAPPY DAY
ユーザー face4face4
提出日時 2019-09-26 11:54:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 19 ms / 5,000 ms
コード長 1,148 bytes
コンパイル時間 874 ms
コンパイル使用メモリ 66,436 KB
実行使用メモリ 8,680 KB
最終ジャッジ日時 2023-10-24 15:21:29
合計ジャッジ時間 1,480 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,612 KB
testcase_01 AC 2 ms
5,716 KB
testcase_02 AC 2 ms
5,612 KB
testcase_03 AC 3 ms
5,700 KB
testcase_04 AC 3 ms
5,700 KB
testcase_05 AC 2 ms
5,708 KB
testcase_06 AC 2 ms
5,700 KB
testcase_07 AC 2 ms
5,708 KB
testcase_08 AC 3 ms
5,700 KB
testcase_09 AC 3 ms
5,708 KB
testcase_10 AC 3 ms
5,708 KB
testcase_11 AC 2 ms
5,708 KB
testcase_12 AC 2 ms
5,708 KB
testcase_13 AC 7 ms
6,976 KB
testcase_14 AC 9 ms
7,080 KB
testcase_15 AC 9 ms
7,568 KB
testcase_16 AC 11 ms
7,572 KB
testcase_17 AC 11 ms
7,328 KB
testcase_18 AC 9 ms
7,568 KB
testcase_19 AC 12 ms
7,732 KB
testcase_20 AC 4 ms
5,744 KB
testcase_21 AC 5 ms
6,500 KB
testcase_22 AC 3 ms
5,840 KB
testcase_23 AC 11 ms
7,504 KB
testcase_24 AC 10 ms
6,848 KB
testcase_25 AC 19 ms
8,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
typedef long long ll;

const ll mod = 1e9+9;

int dp1[202][2][2000] = {};
int dp2[202][2][2000] = {};

void f(const string s, int dp[202][2][2000]){
    int n = s.length();
    dp[0][0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 2; j++){
            for(int k = 0; k < 2000; k++){
                if(dp[i][j][k] == 0)    continue;
                for(int num = 0; num < 10; num++){
                    if(j == 0 && num > s[i]-'0')    break;
                    int ni = i+1;
                    int nj = j | (num < s[i]-'0');
                    int nk = k+num;
                    dp[ni][nj][nk] += dp[i][j][k];
                    dp[ni][nj][nk] %= mod;
                }
            }
        }
    }
}

int main(){
    string m, d;
    cin >> m >> d;
    f(m, dp1);    
    f(d, dp2);
    ll ans = 0;
    int mlen = m.length(), dlen = d.length();
    for(int i = 1; i < 2000; i++){
        ll a = (dp1[mlen][0][i]+dp1[mlen][1][i])%mod;
        ll b = (dp2[dlen][0][i]+dp2[dlen][1][i])%mod;
        ans += a*b%mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}
0