結果

問題 No.1086 桁和の桁和2
ユーザー kriiikriii
提出日時 2020-06-19 23:02:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,198 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 45,300 KB
実行使用メモリ 4,960 KB
最終ジャッジ日時 2023-09-16 15:13:45
合計ジャッジ時間 3,858 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 45 ms
4,888 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 29 ms
4,376 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 37 ms
4,452 KB
testcase_14 AC 23 ms
4,380 KB
testcase_15 AC 14 ms
4,380 KB
testcase_16 AC 77 ms
4,380 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 107 ms
4,932 KB
testcase_19 AC 88 ms
4,508 KB
testcase_20 AC 12 ms
4,380 KB
testcase_21 AC 75 ms
4,380 KB
testcase_22 AC 106 ms
4,896 KB
testcase_23 AC 66 ms
4,376 KB
testcase_24 AC 46 ms
4,376 KB
testcase_25 AC 90 ms
4,680 KB
testcase_26 AC 74 ms
4,380 KB
testcase_27 AC 54 ms
4,376 KB
testcase_28 AC 45 ms
4,380 KB
testcase_29 AC 50 ms
4,380 KB
testcase_30 AC 110 ms
4,960 KB
testcase_31 AC 109 ms
4,912 KB
testcase_32 AC 110 ms
4,956 KB
testcase_33 AC 110 ms
4,960 KB
testcase_34 AC 109 ms
4,924 KB
testcase_35 AC 46 ms
4,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
using namespace std;

int N, D[100100];
long long L[100100], R[100100], B[77], BB[77];

const int mod = 1000000007;

int main()
{
	B[0] = 10; BB[0] = 1;
	for (int i = 1; i < 70; i++){
		B[i] = B[i - 1] * B[i - 1] % mod;
		BB[i] = BB[i - 1] * (B[i - 1] + 1) % mod;
	}

	scanf ("%d", &N);
	for (int i = 0; i < N; i++) scanf ("%lld", &L[i]);
	for (int i = 0; i < N; i++) scanf ("%lld", &R[i]);
	for (int i = 0; i < N; i++) scanf ("%d", &D[i]);

	int s = 0;
	while (s < N && D[s] == 0) s++;

	for (int i = s; i < N; i++) if (D[i] == 0){
		puts("0");
		return 0;
	}

	for (int i = s; i < N; i++){
		L[i - s] = L[i];
		R[i - s] = R[i];
		D[i - s] = D[i];
	}
	N -= s;

	long long ans = 1;
	for (int i = 0; i < N; i++){
		int p = 0;
		long long upp = R[i] - L[i];
		for (int b = 0; upp; b++){
			if (upp & 1) p = (B[b] * p + BB[b]) % mod;
			upp /= 2;
		}

		long long low = L[i];
		for (int b = 0; low; b++){
			if (low & 1) p = B[b] * p % mod;
			low /= 2;
		}

		ans = ans * (p + (i > 0 && D[i-1] == D[i])) % mod;
	}

	bool g = N > 0;
	for (int i = 0; i < N; i++) if (D[i] != 9) g = 0;
	if (g) ans = (ans + mod - 1) % mod;
	
	printf ("%lld\n", ans);

	return 0;
}
0