結果

問題 No.189 SUPER HAPPY DAY
ユーザー face4face4
提出日時 2019-09-26 11:53:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 1,148 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 66,140 KB
実行使用メモリ 8,652 KB
最終ジャッジ日時 2023-10-24 15:21:27
合計ジャッジ時間 1,386 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,556 KB
testcase_01 AC 2 ms
5,660 KB
testcase_02 AC 2 ms
5,556 KB
testcase_03 AC 2 ms
5,644 KB
testcase_04 AC 2 ms
5,644 KB
testcase_05 AC 2 ms
5,652 KB
testcase_06 AC 2 ms
5,644 KB
testcase_07 AC 2 ms
5,652 KB
testcase_08 AC 2 ms
5,644 KB
testcase_09 AC 2 ms
5,652 KB
testcase_10 AC 2 ms
5,652 KB
testcase_11 AC 2 ms
5,652 KB
testcase_12 AC 2 ms
5,652 KB
testcase_13 AC 7 ms
6,920 KB
testcase_14 AC 8 ms
7,056 KB
testcase_15 AC 8 ms
7,512 KB
testcase_16 AC 10 ms
7,516 KB
testcase_17 AC 11 ms
7,300 KB
testcase_18 AC 9 ms
7,512 KB
testcase_19 AC 11 ms
7,708 KB
testcase_20 AC 4 ms
5,720 KB
testcase_21 AC 4 ms
6,444 KB
testcase_22 AC 2 ms
5,784 KB
testcase_23 AC 10 ms
7,448 KB
testcase_24 AC 9 ms
6,820 KB
testcase_25 AC 18 ms
8,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const ll mod = 1e9+9;

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

void f(const string s, int dp[205][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