結果

問題 No.189 SUPER HAPPY DAY
ユーザー drken1215
提出日時 2015-04-22 00:46:37
言語 C++11
(gcc 4.8.5)
結果
AC  
実行時間 34 ms
コード長 2,986 Byte
コンパイル時間 315 ms
使用メモリ 22,200 KB
最終ジャッジ日時 2019-03-17 00:39:34

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
00_sample01.in AC 11 ms
22,168 KB
00_sample02.in AC 11 ms
22,184 KB
00_sample03.in AC 11 ms
22,172 KB
10_random_small01.in AC 12 ms
22,184 KB
10_random_small02.in AC 12 ms
22,188 KB
10_random_small03.in AC 12 ms
22,184 KB
10_random_small04.in AC 11 ms
22,184 KB
10_random_small05.in AC 12 ms
22,184 KB
10_random_small06.in AC 12 ms
22,184 KB
10_random_small07.in AC 11 ms
22,184 KB
10_random_small08.in AC 12 ms
22,188 KB
10_random_small09.in AC 12 ms
22,184 KB
10_random_small10.in AC 12 ms
22,184 KB
20_random_large01.in AC 27 ms
22,196 KB
20_random_large02.in AC 31 ms
22,192 KB
20_random_large03.in AC 28 ms
22,192 KB
20_random_large04.in AC 28 ms
22,192 KB
20_random_large05.in AC 30 ms
22,196 KB
20_random_large06.in AC 27 ms
22,196 KB
20_random_large07.in AC 34 ms
22,200 KB
20_random_large08.in AC 20 ms
22,196 KB
20_random_large09.in AC 21 ms
22,192 KB
20_random_large10.in AC 14 ms
22,188 KB
30_corner01.in AC 21 ms
22,192 KB
30_corner02.in AC 21 ms
22,196 KB
30_corner03.in AC 32 ms
22,200 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