結果

問題 No.1086 桁和の桁和2
ユーザー hedwig100hedwig100
提出日時 2020-06-20 16:52:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,136 bytes
コンパイル時間 1,439 ms
コンパイル使用メモリ 169,696 KB
実行使用メモリ 6,456 KB
最終ジャッジ日時 2023-09-16 17:37:23
合計ジャッジ時間 7,027 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 138 ms
5,476 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 86 ms
4,380 KB
testcase_11 AC 24 ms
4,376 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 110 ms
5,016 KB
testcase_14 AC 68 ms
4,376 KB
testcase_15 AC 26 ms
4,380 KB
testcase_16 AC 147 ms
5,284 KB
testcase_17 AC 14 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 176 ms
5,364 KB
testcase_20 AC 23 ms
4,380 KB
testcase_21 AC 152 ms
5,280 KB
testcase_22 AC 208 ms
6,008 KB
testcase_23 AC 127 ms
4,956 KB
testcase_24 AC 90 ms
4,380 KB
testcase_25 AC 177 ms
5,808 KB
testcase_26 AC 145 ms
5,092 KB
testcase_27 AC 104 ms
4,676 KB
testcase_28 AC 87 ms
4,484 KB
testcase_29 WA -
testcase_30 AC 213 ms
6,336 KB
testcase_31 AC 215 ms
6,332 KB
testcase_32 WA -
testcase_33 AC 219 ms
6,456 KB
testcase_34 AC 213 ms
6,276 KB
testcase_35 AC 138 ms
5,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;


struct Debug {
    template<class T> static void print_value(T value,const char* name) {
        cout << name << ": " << value << '\n';
    }
    template<class T> static void print_vector(vector<T> &vec,const char* name) {
        for (int i = 0;i < vec.size();++i) {
            cout << "  " << name;
            printf("[%d]: ",i);
            cout << vec[i];
        }
        cout << '\n';
    }
    template<class T> static void print_2dvector(vector<vector<T>> &vec,const char* name) {
        for (int i = 0;i < vec.size();++i) {
            for (int j = 0;j < vec[i].size();++j) {
                cout << "  " << name;
                printf("[%d][%d]: ",i,j);
                cout << vec[i][j];
            }
            cout << '\n';
        }
    }
    template<class T> static void print_set(set<T> &st,const char* name) {
        int i = 0;
        for (auto itr = st.begin();itr != st.end(); ++itr,++i) {
            cout << "  " << name;
            printf("[%d]: ",i);
            cout << *itr;
        }
        cout << '\n';
    }

    template<class T1,class T2>
    static void print_map(map<T1,T2> &mp,const char* name) {
        for (auto p: mp) {
            cout << "  " << name << '[' << p.first << ']' << ": " << p.second;
        }
        cout << '\n';
    }
};

template<class T> T modpow(T N,long long K,long long mod = MOD) {
    long long ret = 1;
    while (K > 0) {
        if (K&1) {
            ret *= N;
            ret %= mod;
        }
        K >>= 1;
        N *= N;
        N %= mod;
    }
    return ret;
}

int main() {
    int N; cin >> N;
    vector<ll> L(N); rep(i,N) cin >> L[i];
    vector<ll> R(N); rep(i,N) cin >> R[i];
    vector<ll> D(N + 1); rep(i,N) cin >> D[i + 1];
    D[0] = 0;
    bool plus = false;
    bool zero = false;
    rep(i,N) {
        if (D[i + 1] == 0) {
            zero = true;
        }
        else if (D[i + 1] == 9) {
            D[i + 1] = 0;
            plus = true;
        }
        else {
            plus = true;
        }
    }
    if (plus && zero) {
        cout << 0 << endl;
        return 0;
    }
    else if (zero) {
        cout << 1 << endl;
        return 0;
    }
    
    ll inv9 = modpow((ll)9,MOD - 2);
    //Debug::print_value(inv9,"inv9");
    vector<ll> dp(N + 1,0);
    dp[0] = 1;
    rep(i,N) {
        ll x = (modpow((ll)10,R[i]) - modpow((ll)10,L[i]) + MOD)*inv9%MOD;
        //Debug::print_value(x,"x");
        rep(j,9) {
            if (j == 0) {
                if ((j + D[i])%9 == D[i + 1]) dp[i + 1] += dp[i] * (x + 1) % MOD;
            }
            else {
                if ((j + D[i])%9 == D[i + 1]) dp[i + 1] += dp[i] * x % MOD;
            }
            dp[i + 1] %= MOD;
        }
    }
    //Debug::print_vector(dp,"dp");
    cout << dp[N] << endl;
    return 0;
}
0