結果

問題 No.1086 桁和の桁和2
ユーザー milanis48663220milanis48663220
提出日時 2020-06-19 23:29:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 3,000 ms
コード長 1,419 bytes
コンパイル時間 725 ms
コンパイル使用メモリ 83,456 KB
実行使用メモリ 5,844 KB
最終ジャッジ日時 2023-09-29 23:54:51
合計ジャッジ時間 4,355 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 45 ms
5,684 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 28 ms
4,892 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 35 ms
5,228 KB
testcase_14 AC 24 ms
4,740 KB
testcase_15 AC 15 ms
4,376 KB
testcase_16 AC 81 ms
5,012 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 112 ms
5,712 KB
testcase_19 AC 92 ms
5,248 KB
testcase_20 AC 13 ms
4,376 KB
testcase_21 AC 80 ms
4,992 KB
testcase_22 AC 111 ms
5,700 KB
testcase_23 AC 69 ms
4,816 KB
testcase_24 AC 49 ms
4,412 KB
testcase_25 AC 94 ms
5,364 KB
testcase_26 AC 78 ms
4,996 KB
testcase_27 AC 57 ms
4,804 KB
testcase_28 AC 48 ms
4,380 KB
testcase_29 AC 52 ms
4,624 KB
testcase_30 AC 114 ms
5,692 KB
testcase_31 AC 115 ms
5,720 KB
testcase_32 AC 115 ms
5,844 KB
testcase_33 AC 115 ms
5,720 KB
testcase_34 AC 115 ms
5,776 KB
testcase_35 AC 45 ms
5,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

template <typename T>
T pow(T a, ll n) {
	T ans = 1;
	T tmp = a;
	for (int i = 0; i <= 60; i++) {
		ll m = (ll)1 << i;
		if (m & n) {
		ans *= tmp;
		ans %= MOD;
		}
		tmp *= tmp;
		tmp %= MOD;
	}
	return ans;
}

ll inv(ll n){
    if(n == 1) return 1;
    else return MOD-inv(MOD%n)*(MOD/n)%MOD;
}


int N;
ll L[100000], R[100000], D[100000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> L[i];
    for(int i = 0; i < N; i++) cin >> R[i];
    for(int i = 0; i < N; i++) cin >> D[i];
    ll ans = 1;
    int prev = 0;
    int cnt_plus = 0;
    for(int i = 0; i < N; i++){
        if(D[i] == 0){
            if(cnt_plus > 0){
                cout << 0 << endl;
                return 0;
            }
            ans = 1;
        }else{
            ll r = pow<ll>(10, R[i]);
            ll l = pow<ll>(10, L[i]);
            ll d = (r-l+MOD)%MOD;
            ll tmp = (d*inv(9))%MOD;
            if(D[i] == prev) tmp++;
            if(D[i] == 9 && prev == 0 && cnt_plus > 0) tmp++;
            ans *= tmp;
            ans %= MOD;
            cnt_plus++;
        }
        prev = D[i];
    }
    cout << ans << endl;
}
0