結果

問題 No.1086 桁和の桁和2
ユーザー leaf_1415leaf_1415
提出日時 2020-06-19 22:14:29
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 289 ms / 3,000 ms
コード長 2,114 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 75,408 KB
実行使用メモリ 13,020 KB
最終ジャッジ日時 2023-09-29 23:44:59
合計ジャッジ時間 6,949 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,424 KB
testcase_01 AC 2 ms
5,476 KB
testcase_02 AC 2 ms
5,420 KB
testcase_03 AC 2 ms
5,416 KB
testcase_04 AC 2 ms
5,624 KB
testcase_05 AC 45 ms
6,660 KB
testcase_06 AC 2 ms
5,468 KB
testcase_07 AC 3 ms
5,612 KB
testcase_08 AC 2 ms
5,476 KB
testcase_09 AC 2 ms
5,408 KB
testcase_10 AC 29 ms
6,088 KB
testcase_11 AC 9 ms
5,616 KB
testcase_12 AC 3 ms
5,540 KB
testcase_13 AC 36 ms
6,344 KB
testcase_14 AC 23 ms
5,836 KB
testcase_15 AC 37 ms
6,468 KB
testcase_16 AC 204 ms
11,252 KB
testcase_17 AC 18 ms
5,936 KB
testcase_18 AC 282 ms
12,696 KB
testcase_19 AC 232 ms
11,932 KB
testcase_20 AC 31 ms
6,176 KB
testcase_21 AC 199 ms
10,940 KB
testcase_22 AC 280 ms
12,676 KB
testcase_23 AC 171 ms
10,128 KB
testcase_24 AC 120 ms
8,684 KB
testcase_25 AC 236 ms
12,240 KB
testcase_26 AC 195 ms
10,844 KB
testcase_27 AC 141 ms
9,264 KB
testcase_28 AC 118 ms
8,532 KB
testcase_29 AC 132 ms
8,916 KB
testcase_30 AC 288 ms
12,932 KB
testcase_31 AC 288 ms
12,792 KB
testcase_32 AC 289 ms
13,020 KB
testcase_33 AC 289 ms
12,724 KB
testcase_34 AC 289 ms
12,856 KB
testcase_35 AC 45 ms
6,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint l[100005], r[100005], d[100005];
llint dp[100005][9];
llint inv9;

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

llint get(llint k)
{
	llint ret = modpow(10, k+1);
	ret += mod-1, ret %= mod;
	ret *= inv9, ret %= mod;
	return ret;
}

llint calc(llint l, llint r)
{
	llint ret = get(r-1) + mod - get(l-1);
	ret %= mod;
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	inv9 = modpow(9, mod-2);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> l[i];
	for(int i = 1; i <= n; i++) cin >> r[i];
	for(int i = 1; i <= n; i++) cin >> d[i];
	
	for(int i = 1; i <= n-1; i++){
		if(d[i] > 0 && d[i+1] == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	
	llint pos = 0;
	for(int i = n; i >= 1; i--){
		if(d[i] == 0){
			pos = i;
			break;
		}
	}
	
	dp[pos][0] = 1;
	for(int i = pos; i < n; i++){
		llint mul = calc(l[i+1], r[i+1]);
		//cout << i+1 << " " << mul << endl;
		for(int j = 0; j < 9; j++){
			for(int k = 0; k < 9; k++){
				llint nj = (j+k)%9;
				if(nj != d[i+1]%9) continue;
				(dp[i+1][nj] += dp[i][j] * mul % mod) %= mod;
			}
			if(i > pos && d[i+1]%9 == j) (dp[i+1][j] += dp[i][j]) %= mod;
		}
	}
	
	/*for(int i = 0; i <= n; i++){
		for(int j = 0; j < 9; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	
	llint ans = 0;
	for(int i = 0; i < 9; i++) ans += dp[n][i], ans %= mod;
	cout << ans << endl;
	
	return 0;
}
0