結果

問題 No.1086 桁和の桁和2
ユーザー SSRSSSRS
提出日時 2020-06-19 22:47:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 507 ms / 3,000 ms
コード長 1,961 bytes
コンパイル時間 1,695 ms
コンパイル使用メモリ 169,680 KB
実行使用メモリ 7,368 KB
最終ジャッジ日時 2023-09-29 23:50:20
合計ジャッジ時間 10,901 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 140 ms
5,008 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 88 ms
4,376 KB
testcase_11 AC 24 ms
4,376 KB
testcase_12 AC 6 ms
4,380 KB
testcase_13 AC 111 ms
4,576 KB
testcase_14 AC 70 ms
4,380 KB
testcase_15 AC 61 ms
4,380 KB
testcase_16 AC 354 ms
5,844 KB
testcase_17 AC 31 ms
4,380 KB
testcase_18 AC 491 ms
7,368 KB
testcase_19 AC 403 ms
6,544 KB
testcase_20 AC 51 ms
4,376 KB
testcase_21 AC 347 ms
5,952 KB
testcase_22 AC 490 ms
7,280 KB
testcase_23 AC 300 ms
5,692 KB
testcase_24 AC 208 ms
5,020 KB
testcase_25 AC 413 ms
6,592 KB
testcase_26 AC 338 ms
5,848 KB
testcase_27 AC 244 ms
5,096 KB
testcase_28 AC 205 ms
4,672 KB
testcase_29 AC 227 ms
4,836 KB
testcase_30 AC 504 ms
7,280 KB
testcase_31 AC 504 ms
7,192 KB
testcase_32 AC 507 ms
7,336 KB
testcase_33 AC 506 ms
7,164 KB
testcase_34 AC 506 ms
7,276 KB
testcase_35 AC 140 ms
4,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long modsub(long long a, long long b){
	a %= MOD;
	b %= MOD;
	if (a >= b){
		return (a - b) % MOD;
	} else {
		return MOD - (b - a) % MOD;
	}
}
long long modpow(long long a, long long b){
	a %= MOD;
	long long res = 1;
	while (b > 0){
		if (b % 2 == 1) res = res * a % MOD;
		a = a * a % MOD;
		b = b / 2;
	}
	return res;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
long long modrepunit(long long x){
  return modsub(modpow(10, x), 1) * modinv(9) % MOD;
}
int main(){
  int N;
  cin >> N;
  vector<long long> L(N);
  for (int i = 0; i < N; i++){
    cin >> L[i];
  }
  vector<long long> R(N);
  for (int i = 0; i < N; i++){
    cin >> R[i];
  }
  vector<int> D(N);
  for (int i = 0; i < N; i++){
    cin >> D[i];
  }
  bool ok = true;
  for (int i = 0; i < N - 1; i++){
    if (D[i] != 0 && D[i + 1] == 0){
      ok = false;
    }
  }
  if (!ok){
    cout << 0 << endl;
  } else {
    int pos = 0;
    for (int i = 0; i < N; i++){
      if (D[i] == 0){
        pos = i + 1;
      } else {
        break;
      }
    }
    if (pos == N){
      cout << 1 << endl;
    } else {
      vector<long long> L2(N - pos);
      for (int i = pos; i < N; i++){
        L2[i - pos] = L[i];
      }
      vector<long long> R2(N - pos);
      for (int i = pos; i < N; i++){
        R2[i - pos] = R[i];
      }
      vector<int> D2(N - pos);
      for (int i = pos; i < N; i++){
        D2[i - pos] = D[i];
      }
      N -= pos;
      vector<int> D3(N, 0);
      D3[0] = D2[0] % 9;
      for (int i = 1; i < N; i++){
        D3[i] = (D2[i] - D2[i - 1] + 9) % 9;
      }
      long long ans = 1;
      for (int i = 0; i < N; i++){
        long long tmp = (modrepunit(R2[i]) - modrepunit(L2[i]) + MOD) % MOD;
        if (D3[i] == 0 && i != 0){
          tmp++;
          tmp %= MOD;
        }
        ans *= tmp;
        ans %= MOD;
      }
      cout << ans << endl;
    }
  }
}
0