結果

問題 No.1086 桁和の桁和2
ユーザー Y17Y17
提出日時 2020-06-19 22:59:41
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 252 ms / 3,000 ms
コード長 1,155 bytes
コンパイル時間 1,485 ms
コンパイル使用メモリ 165,308 KB
実行使用メモリ 6,532 KB
最終ジャッジ日時 2023-09-29 23:53:12
合計ジャッジ時間 7,776 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 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 240 ms
6,456 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 150 ms
5,544 KB
testcase_11 AC 42 ms
4,480 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 190 ms
5,964 KB
testcase_14 AC 120 ms
5,356 KB
testcase_15 AC 32 ms
4,472 KB
testcase_16 AC 176 ms
5,832 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 244 ms
6,368 KB
testcase_19 AC 201 ms
6,000 KB
testcase_20 AC 27 ms
4,376 KB
testcase_21 AC 173 ms
5,960 KB
testcase_22 AC 243 ms
6,360 KB
testcase_23 AC 149 ms
5,512 KB
testcase_24 AC 104 ms
5,312 KB
testcase_25 AC 206 ms
5,996 KB
testcase_26 AC 168 ms
5,684 KB
testcase_27 AC 122 ms
5,264 KB
testcase_28 AC 102 ms
5,068 KB
testcase_29 AC 113 ms
5,140 KB
testcase_30 AC 251 ms
6,472 KB
testcase_31 AC 251 ms
6,532 KB
testcase_32 AC 252 ms
6,428 KB
testcase_33 AC 252 ms
6,432 KB
testcase_34 AC 251 ms
6,460 KB
testcase_35 AC 245 ms
6,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define MOD 1000000007 

int n;
int l[100010];
int r[100010]; 
int d[100010];

int pow_mod(int n, int m){
	int ans = 1;
	while(m > 0){
		if(m & 1) ans = (ans * n) % MOD;
		n = (n * n) % MOD;
		m >>= 1;
	}
	return ans;
}

int get(int i){
	int a = (MOD + pow_mod(10, i)-1)%MOD;
	return a*pow_mod(9, MOD-2) % MOD;
}

signed main(){

	int n;
	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+1];

	d[0] = 0;
	int dp[100010] = {};
	dp[0] = 1;
	for(int x = 0;x < n;x++){
		for(int i = 0;i < 10;i++){
			int num = (d[x] + i) % 9;
			if(num == 0 && (d[x] != 0 || i != 0)){
				num = 9;
			}
			if(num == d[x+1]){
				if(i == 0){
					dp[x+1] += dp[x];
					dp[x+1] %= MOD;
				}else{
					int num = (MOD+get(r[x])-get(l[x]))%MOD;
					dp[x+1] += dp[x] * num %MOD;
					dp[x+1] %= MOD;
				}
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}
0