結果

問題 No.1086 桁和の桁和2
ユーザー QCFiumQCFium
提出日時 2020-06-19 23:51:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 38 ms / 3,000 ms
コード長 1,651 bytes
コンパイル時間 1,518 ms
コンパイル使用メモリ 167,240 KB
実行使用メモリ 9,644 KB
最終ジャッジ日時 2023-09-29 23:58:54
合計ジャッジ時間 4,001 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 37 ms
9,452 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 25 ms
8,716 KB
testcase_11 AC 8 ms
4,384 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 29 ms
9,216 KB
testcase_14 AC 19 ms
6,280 KB
testcase_15 AC 6 ms
4,376 KB
testcase_16 AC 26 ms
8,884 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 38 ms
9,404 KB
testcase_19 AC 32 ms
9,048 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 26 ms
8,844 KB
testcase_22 AC 37 ms
9,564 KB
testcase_23 AC 25 ms
8,668 KB
testcase_24 AC 17 ms
5,836 KB
testcase_25 AC 34 ms
9,144 KB
testcase_26 AC 26 ms
8,980 KB
testcase_27 AC 18 ms
6,252 KB
testcase_28 AC 16 ms
5,860 KB
testcase_29 AC 18 ms
6,064 KB
testcase_30 AC 37 ms
9,492 KB
testcase_31 AC 35 ms
9,444 KB
testcase_32 AC 37 ms
9,644 KB
testcase_33 AC 36 ms
9,448 KB
testcase_34 AC 35 ms
9,460 KB
testcase_35 AC 38 ms
9,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

struct FastIO {
	char buf[10000000];
	char *ptr = buf;
	void read() {
		int size;
		size = fread(buf, 1, sizeof(buf) - 1, stdin);
		buf[size] = '\0';
		ptr = buf;
	}
	FastIO () {
		read();
	}
	void inc() {
		ptr++;
	}
	template<typename Integer> Integer read() {
		bool neg = false;
		Integer res = 0;
		while ((*ptr < '0' || *ptr > '9') && *ptr != '-') inc();
		if (*ptr == '-') neg = true, inc();
		while (*ptr >= '0' && *ptr <= '9') res = res * 10 + *ptr - '0', inc();
		return neg ? -res : res;
	}
} fastio;
#define ri fastio.read<int>
#define rs64 fastio.read<int64_t>

#define MOD 1000000007

int mpow(int a, int64_t b) {
	b %= 1000000006;
	int res = 1;
	for (; b; b >>= 1) {
		if (b & 1) res = (int64_t) res * a % MOD;
		a = (int64_t) a * a % MOD;
	}
	return res;
}

int main() {
	int n = ri();
	int64_t l[n], r[n];
	int d[n];
	for (auto &i : l) i = rs64();
	for (auto &i : r) i = rs64();
	for (auto &i : d) i = ri();
	
	int head = 0;
	while (head < n && !d[head]) head++;
	
	int pow10[31] = { 10 };
	for (int i = 0; i < 30; i++) pow10[i + 1] = (int64_t) pow10[i] * pow10[i] % MOD;
	auto mpow10 = [&] (int64_t b) {
		b %= 1000000006;
		int res = 1;
		for (int i = 0; b; b >>= 1, i++) if (b & 1) res = (int64_t) res * pow10[i] % MOD;
		return res;
	};
	
	int res = 1;
	for (int i = head; i < n; i++) {
		if (!d[i]) res = 0;
		int diff = (d[i] - (i ? d[i - 1] : 0)) % 9;
		int times = (!diff && i != head) + (int64_t) (mpow10(r[i]) - mpow10(l[i])) * 111111112 % MOD;
		res = (int64_t) res * times % MOD;
	}
	if (res < 0) res += MOD;
	printf("%d\n", res);
	return 0;
}

0