結果

問題 No.1086 桁和の桁和2
ユーザー QCFiumQCFium
提出日時 2020-06-19 23:50:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 3,000 ms
コード長 1,692 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 167,624 KB
実行使用メモリ 6,596 KB
最終ジャッジ日時 2023-09-29 23:58:59
合計ジャッジ時間 4,335 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 41 ms
6,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 26 ms
5,652 KB
testcase_11 AC 8 ms
4,504 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 33 ms
5,980 KB
testcase_14 AC 22 ms
5,460 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 29 ms
6,016 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 40 ms
6,412 KB
testcase_19 AC 34 ms
6,132 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 29 ms
5,784 KB
testcase_22 AC 40 ms
6,320 KB
testcase_23 AC 25 ms
5,732 KB
testcase_24 AC 18 ms
5,248 KB
testcase_25 AC 35 ms
6,048 KB
testcase_26 AC 28 ms
5,736 KB
testcase_27 AC 21 ms
5,372 KB
testcase_28 AC 18 ms
5,224 KB
testcase_29 AC 20 ms
5,392 KB
testcase_30 AC 41 ms
6,596 KB
testcase_31 AC 41 ms
6,392 KB
testcase_32 AC 41 ms
6,396 KB
testcase_33 AC 41 ms
6,388 KB
testcase_34 AC 41 ms
6,592 KB
testcase_35 AC 42 ms
6,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

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

struct FastIO {
	char buf[1000000];
	char *ptr = buf;
	void read() {
		int size;
		size = fread(buf, 1, sizeof(buf) - 1, stdin);
		buf[size] = '\0';
		ptr = buf;
	}
	FastIO () {
		read();
	}
	void inc() {
		if (++ptr == buf + sizeof(buf) || !*ptr) read();
	}
	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