結果

問題 No.189 SUPER HAPPY DAY
ユーザー mamekinmamekin
提出日時 2015-05-24 14:11:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,661 bytes
コンパイル時間 711 ms
コンパイル使用メモリ 95,972 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 11:14:18
合計ジャッジ時間 1,993 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 6 ms
4,376 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 8 ms
4,380 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 10 ms
4,376 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 11 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 10 ms
4,376 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 17 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

const int MOD = 1000000009;

vector<int> solve(const string& s)
{
    int n = s.size();
    vector<vector<int> > dp(2, vector<int>(1, 0));
    dp[0][0] = 1;

    for(int i=0; i<n; ++i){
        vector<vector<int> > nextDp(2, vector<int>(dp[0].size() + 9, 0));
        for(int j=0; j<2; ++j){
            for(unsigned k=0; k<dp[j].size(); ++k){
                for(int a=0; a<=9; ++a){
                    if(j == 0 && a == s[i] - '0'){
                        nextDp[0][k+a] += dp[j][k];
                        nextDp[0][k+a] %= MOD;
                    }
                    else if(j == 1 || a < s[i] - '0'){
                        nextDp[1][k+a] += dp[j][k];
                        nextDp[1][k+a] %= MOD;
                    }
                }
            }
        }
        dp.swap(nextDp);
    }

    vector<int> ans(dp[0].size());
    for(unsigned i=0; i<dp[0].size(); ++i){
        ans[i] = dp[0][i] + dp[1][i];
        ans[i] %= MOD;
    }
    return ans;
}

int main()
{
    string m, d;
    cin >> m >> d;

    vector<int> a = solve(m);
    vector<int> b = solve(d);
    int n = min(a.size(), b.size());
    long long ans = 0;
    for(int i=1; i<n; ++i){
        ans += a[i] * (long long)b[i];
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}
0