結果

問題 No.189 SUPER HAPPY DAY
ユーザー drken1215drken1215
提出日時 2015-04-22 00:46:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 2,986 bytes
コンパイル時間 444 ms
コンパイル使用メモリ 60,492 KB
実行使用メモリ 24,316 KB
最終ジャッジ日時 2023-09-18 06:28:49
合計ジャッジ時間 1,851 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
24,092 KB
testcase_01 AC 9 ms
24,024 KB
testcase_02 AC 8 ms
24,020 KB
testcase_03 AC 9 ms
24,028 KB
testcase_04 AC 9 ms
24,032 KB
testcase_05 AC 9 ms
24,036 KB
testcase_06 AC 9 ms
24,084 KB
testcase_07 AC 9 ms
24,316 KB
testcase_08 AC 9 ms
24,032 KB
testcase_09 AC 9 ms
24,284 KB
testcase_10 AC 9 ms
24,028 KB
testcase_11 AC 9 ms
24,148 KB
testcase_12 AC 9 ms
24,016 KB
testcase_13 AC 18 ms
24,036 KB
testcase_14 AC 22 ms
24,032 KB
testcase_15 AC 19 ms
24,088 KB
testcase_16 AC 20 ms
24,040 KB
testcase_17 AC 22 ms
24,044 KB
testcase_18 AC 19 ms
24,092 KB
testcase_19 AC 25 ms
24,188 KB
testcase_20 AC 14 ms
24,032 KB
testcase_21 AC 16 ms
24,096 KB
testcase_22 AC 11 ms
24,144 KB
testcase_23 AC 15 ms
24,036 KB
testcase_24 AC 16 ms
24,044 KB
testcase_25 AC 23 ms
24,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }



const long long MOD = 1000000009;

string st1, st2;
long long dp1[210][2100][3], dp2[210][2100][3];

int main() {
    while (cin >> st1 >> st2) {
        memset(dp1, 0, sizeof(dp1));
        memset(dp2, 0, sizeof(dp2));
        
        int n1 = st1.size();
        st1 += ' ';
        int n2 = st2.size();
        st2 += ' ';
        
        dp1[0][0][0] = 1;
        for (int i = 0; i <= n1; ++i) {
            for (int j = 0; j < 2000; ++j) {
                //if (dp1[i][j][0] || dp1[i][j][1]) cout << i << ", " << j << ": " << make_pair(dp1[i][j][0], dp1[i][j][1]) << endl;
                
                // from smaller
                for (int k = 0; k <= 9; ++k) {
                    (dp1[i+1][j+k][1] += dp1[i][j][1]) %= MOD;
                }
                
                // from exact
                for (int k = 0; k <= 9; ++k) {
                    if (k > st1[i]-'0') break;
                    if (k == st1[i] - '0') {
                        (dp1[i+1][j+k][0] += dp1[i][j][0]) %= MOD;
                    }
                    else {
                        (dp1[i+1][j+k][1] += dp1[i][j][0]) %= MOD;
                    }
                }
            }
        }
        
        dp2[0][0][0] = 1;
        for (int i = 0; i <= n2; ++i) {
            for (int j = 0; j < 2000; ++j) {
                
                // from smaller
                for (int k = 0; k <= 9; ++k) {
                    (dp2[i+1][j+k][1] += dp2[i][j][1]) %= MOD;
                }
                
                // from exact
                for (int k = 0; k <= 9; ++k) {
                    if (k > st2[i]-'0') break;
                    if (k == st2[i] - '0') {
                        (dp2[i+1][j+k][0] += dp2[i][j][0]) %= MOD;
                    }
                    else {
                        (dp2[i+1][j+k][1] += dp2[i][j][0]) %= MOD;
                    }
                }
            }
        }
            
        long long res = 0;
        for (int j = 1; j <= 2000; ++j) {
            res += (dp1[n1][j][0] + dp1[n1][j][1]) * (dp2[n2][j][0] + dp2[n2][j][1]);
            res %= MOD;
        }
        
        cout << res << endl;
    }
}





0