結果

問題 No.1084 積の積
ユーザー keijakkeijak
提出日時 2020-06-19 23:06:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 2,652 bytes
コンパイル時間 2,301 ms
コンパイル使用メモリ 203,520 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-16 15:16:33
合計ジャッジ時間 3,935 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 52 ms
4,376 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 53 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 13 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 16 ms
4,376 KB
testcase_13 AC 33 ms
4,380 KB
testcase_14 AC 13 ms
4,380 KB
testcase_15 AC 12 ms
4,384 KB
testcase_16 AC 37 ms
4,376 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 25 ms
4,388 KB
testcase_19 AC 33 ms
4,380 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 13 ms
4,376 KB
testcase_22 AC 10 ms
4,380 KB
testcase_23 AC 21 ms
4,380 KB
testcase_24 AC 18 ms
4,380 KB
testcase_25 AC 33 ms
4,376 KB
testcase_26 AC 35 ms
4,376 KB
testcase_27 AC 33 ms
4,380 KB
testcase_28 AC 33 ms
4,380 KB
testcase_29 AC 33 ms
4,380 KB
testcase_30 AC 34 ms
4,376 KB
testcase_31 AC 33 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define debug(...)
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    debug(__VA_ARGS__);                \
    cerr << endl;                      \
  } while (0)
#endif

// auto mod int

const i64 MOD = 1'000'000'007;

struct mint {
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<i64> A(N);
  bool has_zero = false;
  for (auto& x : A) {
    cin >> x;
    if (x == 0) has_zero = true;
  }
  if (has_zero) {
    cout << 0 << endl;
    return 0;
  }
  int head = 0, tail = 0;
  mint ans = 1;
  mint cum = 1;
  i64 tmp = 1;
  while (head < N) {
    for (; tail < N; tail++) {
      if (tmp * A[tail] >= 1'000'000'000LL) {
        break;
      }
      tmp *= A[tail];
      cum *= tmp;
      ans *= tmp;
    }
    for (; head < N;) {
      cum *= mint(A[head]).inv().pow(tail - head);
      tmp /= A[head];
      head++;
      if (tmp < 1'000'000'000LL) {
        ans *= cum;
      }
      if (tail < N && tmp * A[tail] < 1'000'000'000LL) {
        break;
      }
    }
  }
  cout << ans << endl;
}
0