結果

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

テストケース

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

ソースコード

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;
    rep(i,N) {
        if (D[i + 1] == 9) D[i + 1] = 0;
        if (D[i + 1] == 0) {
            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