結果

問題 No.1086 桁和の桁和2
ユーザー risujirohrisujiroh
提出日時 2020-06-19 22:05:05
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 118 ms / 3,000 ms
コード長 1,991 bytes
コンパイル時間 2,097 ms
コンパイル使用メモリ 204,488 KB
実行使用メモリ 5,368 KB
最終ジャッジ日時 2023-09-29 23:43:47
合計ジャッジ時間 5,913 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 45 ms
5,288 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 28 ms
4,560 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 35 ms
4,908 KB
testcase_14 AC 23 ms
4,528 KB
testcase_15 AC 16 ms
4,376 KB
testcase_16 AC 83 ms
4,404 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 114 ms
4,920 KB
testcase_19 AC 93 ms
4,564 KB
testcase_20 AC 13 ms
4,380 KB
testcase_21 AC 81 ms
4,376 KB
testcase_22 AC 114 ms
4,888 KB
testcase_23 AC 70 ms
4,380 KB
testcase_24 AC 50 ms
4,376 KB
testcase_25 AC 96 ms
4,680 KB
testcase_26 AC 79 ms
4,384 KB
testcase_27 AC 57 ms
4,376 KB
testcase_28 AC 48 ms
4,376 KB
testcase_29 AC 53 ms
4,380 KB
testcase_30 AC 117 ms
4,824 KB
testcase_31 AC 117 ms
4,836 KB
testcase_32 AC 118 ms
4,836 KB
testcase_33 AC 118 ms
4,948 KB
testcase_34 AC 118 ms
4,876 KB
testcase_35 AC 45 ms
5,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T, class Op = multiplies<T>>
constexpr T power(T a, long long n, Op op = Op(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  static constexpr unsigned mod = M;
  unsigned v;
  modular(long long x = 0) : v((x %= mod) < 0 ? x + mod : x) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m b) { if ((int)(v += b.v - mod) < 0) v += mod; return *this; }
  m& operator-=(m b) { if ((int)(v -= b.v) < 0) v += mod; return *this; }
  m& operator*=(m b) { v = (uint64_t)v * b.v % mod; return *this; }
  m& operator/=(m b) { return *this *= power(b, mod - 2); }
  friend m operator+(m a, m b) { return a += b; }
  friend m operator-(m a, m b) { return a -= b; }
  friend m operator*(m a, m b) { return a *= b; }
  friend m operator/(m a, m b) { return a /= b; }
  friend bool operator==(m a, m b) { return a.v == b.v; }
};

using mint = modular<power(10, 9) + 7>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> l(n), r(n);
  vector<int> d(n);
  for (auto&& e : l) cin >> e;
  for (auto&& e : r) cin >> e;
  for (auto&& e : d) cin >> e;
  for (int i = 1; i < n; ++i) {
    if (d[i - 1] and d[i] == 0) {
      cout << "0\n";
      exit(0);
    }
  }
  {
    int p = 0;
    while (p < n and d[p] == 0) {
      ++p;
    }
    l.erase(begin(l), begin(l) + p);
    r.erase(begin(r), begin(r) + p);
    d.erase(begin(d), begin(d) + p);
    n = size(l);
  }
  mint res = 1;
  for (int i = 0; i < n; ++i) {
    int diff = d[i];
    if (i) {
      diff -= d[i - 1];
      diff += 9;
      diff %= 9;
    }
    res *= (power<mint>(10, r[i]) - power<mint>(10, l[i])) / 9 + (diff == 0);
    if (diff == 0 and i == 0) {
      res -= 1;
    }
  }
  cout << res.v << '\n';
}
0