結果

問題 No.1086 桁和の桁和2
ユーザー potoooooooopotoooooooo
提出日時 2020-06-19 22:30:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,352 ms / 3,000 ms
コード長 1,631 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 207,564 KB
実行使用メモリ 5,540 KB
最終ジャッジ日時 2023-09-29 23:47:42
合計ジャッジ時間 22,076 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 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 45 ms
5,356 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 29 ms
4,624 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 37 ms
4,864 KB
testcase_14 AC 23 ms
4,376 KB
testcase_15 AC 162 ms
4,380 KB
testcase_16 AC 942 ms
4,496 KB
testcase_17 AC 79 ms
4,380 KB
testcase_18 AC 1,306 ms
5,396 KB
testcase_19 AC 1,074 ms
4,832 KB
testcase_20 AC 134 ms
4,376 KB
testcase_21 AC 927 ms
4,548 KB
testcase_22 AC 1,318 ms
5,364 KB
testcase_23 AC 798 ms
4,376 KB
testcase_24 AC 551 ms
4,376 KB
testcase_25 AC 1,097 ms
4,812 KB
testcase_26 AC 901 ms
4,552 KB
testcase_27 AC 650 ms
4,376 KB
testcase_28 AC 539 ms
4,376 KB
testcase_29 AC 604 ms
4,376 KB
testcase_30 AC 1,343 ms
5,344 KB
testcase_31 AC 1,345 ms
5,304 KB
testcase_32 AC 1,349 ms
5,276 KB
testcase_33 AC 1,350 ms
5,464 KB
testcase_34 AC 1,352 ms
5,540 KB
testcase_35 AC 46 ms
5,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1000000007;

long long repeat(long long l) {
    vector<vector<long long>> x = {{10, 0}, {1, 1}};
    vector<long long> v = {1, 0};
    
    auto sq = [&](auto &x) {
        auto y = x;
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 2; j++) {
                y[i][j] = 0;
                for (int k = 0; k < 2; k++) {
                    y[i][j] += x[i][k] * x[k][j] % mod;
                }
                y[i][j] %= mod;
            }
        }
        return y;
    };

    auto mul = [&](auto &x, auto &v) {
        auto ret = v;
        for (int i = 0; i < 2; i++) {
            ret[i] = 0;
            for (int j = 0; j < 2; j++) {
                ret[i] += x[i][j] * v[j] % mod; 
            }
            ret[i] %= mod;
        }
        return ret;
    };

    while (l) {
        if (l & 1) v = mul(x, v);
        x = sq(x);
        l >>= 1;
    }

    return v[1];
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    vector<long long> L(N), R(N), D(N);
    for (auto &x: L) cin >> x;
    for (auto &x: R) cin >> x;
    for (auto &x: D) cin >> x;
    
    int Dc = 0;
    long long Ans = 1;
    
    for (int i = 0; i < N && Ans; i++) {
        if (D[i] == 0) {
            if (Dc != 0) Ans = 0;
            continue;
        }
        int Diff = (D[i] - Dc + 9) % 9;
        long long U = repeat(R[i]) - repeat(L[i]);
        U = (U % mod + mod) % mod;
        if (Diff == 0 && Dc != 0) U++;
        Dc = D[i];
        Ans = Ans * U % mod;
    }
    cout << Ans << "\n";
    return 0;
}
0