結果

問題 No.1086 桁和の桁和2
ユーザー tarattata1tarattata1
提出日時 2020-06-19 23:05:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 98 ms / 3,000 ms
コード長 2,352 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 83,820 KB
実行使用メモリ 4,528 KB
最終ジャッジ日時 2023-09-29 23:53:03
合計ジャッジ時間 4,179 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 46 ms
4,452 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 29 ms
4,376 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 37 ms
4,380 KB
testcase_14 AC 24 ms
4,376 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 70 ms
4,376 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 96 ms
4,416 KB
testcase_19 AC 79 ms
4,380 KB
testcase_20 AC 11 ms
4,376 KB
testcase_21 AC 68 ms
4,380 KB
testcase_22 AC 95 ms
4,412 KB
testcase_23 AC 58 ms
4,376 KB
testcase_24 AC 40 ms
4,376 KB
testcase_25 AC 80 ms
4,380 KB
testcase_26 AC 67 ms
4,380 KB
testcase_27 AC 49 ms
4,376 KB
testcase_28 AC 40 ms
4,380 KB
testcase_29 AC 45 ms
4,376 KB
testcase_30 AC 97 ms
4,436 KB
testcase_31 AC 97 ms
4,412 KB
testcase_32 AC 98 ms
4,448 KB
testcase_33 AC 98 ms
4,528 KB
testcase_34 AC 98 ms
4,480 KB
testcase_35 AC 47 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll minv(ll x){
    return mpow( x, MOD-2 );
}

void solve()
{
    int n;
    scanf("%d", &n);
    vector<ll> L(n), R(n);
    vector<int> D(n);
    int i;
    for (i = 0; i < n; i++) {
        scanf("%lld", &L[i]);
    }
    for (i = 0; i < n; i++) {
        scanf("%lld", &R[i]);
    }
    for (i = 0; i < n; i++) {
        scanf("%d", &D[i]);
    }

    int cnt0 = 0;
    for (i = 0; i < n; i++) {
        if (D[i] == 0) cnt0++;
    }
    if (cnt0 == n) {
        printf("1\n"); return;
    }

    ll ans = 1;
    int prev = -1;
    for (i = 0; i < n; i++) {
        if (D[i] == 0) {
            if (prev!=-1) {
                printf("0\n"); return;
            }
        }
        else {
            D[i] %= 9;
            int add = (D[i] - prev + 9) % 9;
            if (prev < 0) {
                add = D[i] % 9;
            }
            ll ans0 = mpow(10, (R[i] % (MOD - 1)));
            ll ans1 = mpow(10, (L[i] % (MOD - 1)));
            ans0 = (ans0 - ans1 + MOD) % MOD * minv(9) % MOD;
            if (add == 0) {
                ans0 = (ans0 + 1) % MOD;
            }
            if (prev == -1 && D[i]==0) {
                ans0 = (ans0 - 1 + MOD) % MOD;
            }
            ans = ans * ans0 % MOD;

            prev = D[i];
        }
    }
    printf("%lld\n", ans);

    return;
}


int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}
0