結果

問題 No.1084 積の積
ユーザー kichi2004_kichi2004_
提出日時 2020-06-17 21:45:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 4,368 bytes
コンパイル時間 1,521 ms
コンパイル使用メモリ 122,052 KB
実行使用メモリ 4,664 KB
最終ジャッジ日時 2023-09-16 11:42:59
合計ジャッジ時間 2,855 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 2 ms
4,376 KB
testcase_04 AC 29 ms
4,576 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 29 ms
4,548 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 12 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 6 ms
4,376 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 16 ms
4,664 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 11 ms
4,376 KB
testcase_19 AC 14 ms
4,380 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 9 ms
4,376 KB
testcase_25 AC 15 ms
4,376 KB
testcase_26 AC 13 ms
4,640 KB
testcase_27 AC 13 ms
4,548 KB
testcase_28 AC 13 ms
4,536 KB
testcase_29 AC 13 ms
4,536 KB
testcase_30 AC 12 ms
4,552 KB
testcase_31 AC 13 ms
4,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
#include <functional>
#include <set>

using std::cerr;
using std::cin;
using std::cout;
using std::pair;
using std::string;
using std::vector;
//region
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b); i >= (b); --i)
#define rep(i, n) for (unsigned i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n)-1; i >= 0; --i)
#define repr1(i, n) for (int i = (n); i > 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define mset(v, n) std::memset((v), n, sizeof(v))
#define BIT(N) (1LL << (N))
#define each(i, v) for (auto&& i : (v))
#define unless(f) if(!(f))
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using vint = vector<int>;
using vlong = vector<ll>;
using vstr = vector<string>;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpll = vector<pll>;
using vvi = vector<vint>;
using vvl = vector<vlong>;
template<typename T> using VV = vector<vector<T>>;
vector<string> split(const string &s, const string &delim) {
  vector<string> res;
  uint pos = 0;
  while (true) {
    const size_t found = s.find(delim, pos);
    if (found < 0) {
      res.push_back(s.substr(pos));
      break;
    }
    res.push_back(s.substr(pos, found - pos));
    pos = found + delim.size();
  }
  return res;
}
template<typename T> string join(vector<T> &vec, const string &sep) {
  size_t size = vec.size();
  if (!size) return "";
  std::stringstream ss;
  for (int i = 0; i < size - 1; i++)
    ss << vec[i] << sep;
  ss << vec[size - 1];
  return ss.str();
}
template<typename T> std::istream &operator>>(std::istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template<typename Iter> inline void print(const Iter &first, const Iter &last, const std::string &d, bool endline) {
  cout << *first;
  for (Iter iter = first + 1; iter < last; ++iter) {
    cout << d << *iter;
  }
  if (endline) cout << "\n";
}
constexpr ll powmod(ll a, ull b, uint p) {
  ll res = 1;
  while (b > 0) {
    if (b % 2) res = res * a % p;
    a = a * a % p;
    b >>= 1u;
  }
  return res;
}

constexpr ll pow(ll a, ull b) {
  ll res = 1;
  while (b > 0) {
    if (b % 2) res = res * a;
    a = a * a;
    b >>= 1u;
  }
  return res;
}

template<class T> bool chmax(T &a, const T &b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, const T &b) { return a > b ? (a = b, true) : false; }
template <typename T> void bsort(vector<T>& v) { std::sort(v.begin(), v.end()); }
template <typename T> void rsort(vector<T>& v) { std::sort(v.begin(), v.end(), std::greater<T>()); }
struct iii {
    iii() {
      cin.tie(nullptr); cout.tie(nullptr);
      std::ios::sync_with_stdio(false);
      cout << std::fixed << std::setprecision(16);
    }
} init;
//endregion

void solve();

int main() {
  int t = 1;
  //scanf("%d", &t);
  //cin >> t;
  rep(i, t) solve();
  return 0;
}


#include <cassert>
void solve() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  std::cin >> A;
  assert(1 <= N && N <= 100000);
  for (int a : A) {
    assert(0 <= a && a < 1000000000);
  }
  for (int a: A) {
    if (!a) {
      std::cout << 0 << std::endl;
      return;
    }
  }

  std::vector<int> memo(N, -1);
  int right = 0;
  long long m = 1;
  for (int left = 0; left < N; ++left) {
    for (; right < N; ++right) {
      m *= A[right];
      if (m >= 1000000000) {
        m /= A[right];
        memo[left] = right - 1;
        break;
      }
    }
    if (memo[left] == -1) memo[left] = N - 1;
    m /= A[left];
  }

  vector<int> plus(N), minus(N + 2);

  for (int i = 0; i < N; ++i) {
    int all_cnt = N - i - 1;
    int ok_cnt = memo[i] - i;
    int cnt = all_cnt - ok_cnt;

    plus[i] = cnt;
    ++minus[memo[i] + 2];
  }
  long long sum = 0, minus_sum = 0;
  long long ans = 1, cnt2 = 0;
  constexpr int mod = 1000000007;
  rep(i, N) {
    sum += plus[i];
    cnt2 -= i;
    cnt2 += N - i;
    minus_sum += minus[i];
    sum -= minus_sum;
    ll tmp = cnt2 - sum;
    ans *= powmod(A[i], tmp, mod);
    ans %= mod;
  }

  std::cout << ans << std::endl;
}
0