結果

問題 No.1086 桁和の桁和2
ユーザー kappybarkappybar
提出日時 2020-06-21 15:10:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 207 ms / 3,000 ms
コード長 1,370 bytes
コンパイル時間 1,619 ms
コンパイル使用メモリ 167,248 KB
実行使用メモリ 6,436 KB
最終ジャッジ日時 2023-09-30 00:02:10
合計ジャッジ時間 6,203 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 128 ms
6,436 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 79 ms
4,788 KB
testcase_11 AC 21 ms
4,384 KB
testcase_12 AC 5 ms
4,380 KB
testcase_13 AC 98 ms
5,524 KB
testcase_14 AC 62 ms
4,528 KB
testcase_15 AC 24 ms
4,380 KB
testcase_16 AC 134 ms
5,252 KB
testcase_17 AC 12 ms
4,380 KB
testcase_18 AC 190 ms
6,264 KB
testcase_19 AC 160 ms
5,320 KB
testcase_20 AC 21 ms
4,376 KB
testcase_21 AC 134 ms
5,264 KB
testcase_22 AC 186 ms
6,076 KB
testcase_23 AC 116 ms
4,856 KB
testcase_24 AC 82 ms
4,400 KB
testcase_25 AC 163 ms
5,724 KB
testcase_26 AC 134 ms
5,084 KB
testcase_27 AC 98 ms
4,556 KB
testcase_28 AC 83 ms
4,508 KB
testcase_29 AC 89 ms
4,380 KB
testcase_30 AC 206 ms
6,176 KB
testcase_31 AC 203 ms
6,144 KB
testcase_32 AC 200 ms
6,336 KB
testcase_33 AC 207 ms
6,144 KB
testcase_34 AC 194 ms
6,112 KB
testcase_35 AC 127 ms
6,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

long long modpow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = (ret * x) % MOD;  
        x = (x * x) % MOD;
        n >>= 1;  
    }
    return ret;
}

long long inverse(long long x){
    return modpow(x,MOD-2);
}

int main(){
    int n;
    cin >> n;
    vector<ll> l(n),r(n),d(n);
    rep(i,n) cin >> l[i];
    rep(i,n) cin >> r[i];
    rep(i,n) cin >> d[i];

    vector<ll> dp(n+1,0);
    dp[0] = 1;

    ll inv9 = inverse(9);
    for(int i=1;i<=n;i++){
        if(i==1){
            if(d[i-1]==0){
                dp[i] = dp[i-1];
                continue;
            }
        }else{
            if(d[i-1]==0 && d[i-2]>0){
                cout << 0 << endl;
                return 0;
            }else if(d[i-1]==0){
                dp[i] = dp[i-1];
                continue;
            }
        }
        ll res = ((modpow(10,r[i-1]) - modpow(10,l[i-1]) + MOD) * inv9)%MOD;
        if(d[i-1]==d[i-2]) ++ res;
        dp[i] = (dp[i-1] * res)%MOD;
    }
    cout << dp[n] << endl;
    return 0;
}
0