結果

問題 No.1086 桁和の桁和2
ユーザー kriiikriii
提出日時 2020-06-19 23:05:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 3,000 ms
コード長 1,094 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 44,808 KB
実行使用メモリ 4,976 KB
最終ジャッジ日時 2023-09-29 23:53:31
合計ジャッジ時間 3,909 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 46 ms
4,896 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 2 ms
4,380 KB
testcase_10 AC 30 ms
4,380 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 37 ms
4,460 KB
testcase_14 AC 24 ms
4,376 KB
testcase_15 AC 15 ms
4,376 KB
testcase_16 AC 79 ms
4,388 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 108 ms
4,896 KB
testcase_19 AC 89 ms
4,488 KB
testcase_20 AC 12 ms
4,376 KB
testcase_21 AC 77 ms
4,380 KB
testcase_22 AC 107 ms
4,804 KB
testcase_23 AC 67 ms
4,376 KB
testcase_24 AC 47 ms
4,380 KB
testcase_25 AC 91 ms
4,576 KB
testcase_26 AC 75 ms
4,376 KB
testcase_27 AC 55 ms
4,376 KB
testcase_28 AC 46 ms
4,376 KB
testcase_29 AC 51 ms
4,376 KB
testcase_30 AC 111 ms
4,936 KB
testcase_31 AC 111 ms
4,928 KB
testcase_32 AC 111 ms
4,976 KB
testcase_33 AC 111 ms
4,932 KB
testcase_34 AC 111 ms
4,896 KB
testcase_35 AC 46 ms
4,908 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;
	}
	
	printf ("%lld\n", ans);

	return 0;
}
0