結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 141 ms
5,356 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 89 ms
4,380 KB
testcase_11 AC 25 ms
4,376 KB
testcase_12 AC 6 ms
4,376 KB
testcase_13 AC 113 ms
4,876 KB
testcase_14 AC 73 ms
4,380 KB
testcase_15 AC 28 ms
4,380 KB
testcase_16 AC 157 ms
5,216 KB
testcase_17 AC 15 ms
4,376 KB
testcase_18 WA -
testcase_19 AC 178 ms
5,404 KB
testcase_20 AC 24 ms
4,376 KB
testcase_21 AC 153 ms
5,124 KB
testcase_22 AC 218 ms
5,952 KB
testcase_23 AC 132 ms
4,976 KB
testcase_24 AC 92 ms
4,376 KB
testcase_25 AC 182 ms
5,680 KB
testcase_26 AC 151 ms
5,076 KB
testcase_27 AC 108 ms
4,556 KB
testcase_28 AC 91 ms
4,380 KB
testcase_29 WA -
testcase_30 AC 223 ms
6,168 KB
testcase_31 AC 221 ms
6,148 KB
testcase_32 WA -
testcase_33 AC 222 ms
6,148 KB
testcase_34 AC 222 ms
6,272 KB
testcase_35 AC 142 ms
5,476 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;
    int zero = -1;
    rep(i,N) {
        if (D[i + 1] == 0) {
            zero = i;
            if (plus) {
                cout << 0 << endl;
                return 0;
            }
        }
        else if (D[i + 1] == 9) {
            D[i + 1] = 0;
            plus = true;
        }
        else {
            plus = true;
        }
    }
    if (!plus) {
        cout << 1 << endl;
        return 0;
    }
    
    ll inv9 = modpow((ll)9,MOD - 2);
    //Debug::print_value(inv9,"inv9");
    vector<ll> dp(N + 1,0);
    dp[zero + 1] = 1;
    for (int i = zero + 1;i < N;++i) {
        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