結果

問題 No.1084 積の積
ユーザー iqueue02
提出日時 2020-06-19 22:48:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 917 bytes
コンパイル時間 2,472 ms
コンパイル使用メモリ 195,544 KB
最終ジャッジ日時 2025-01-11 07:28:54
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4 RE * 1
other AC * 22 RE * 3 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, int> PL;
constexpr int mod =  1e9 + 7;
constexpr int INF = 1e9;
ll mod_pow(ll x, ll n, ll mod){
    if(n == 0)return 1;
    ll res = mod_pow(x*x%mod,n/2,mod);
    if(n&1) res = res * x % mod;
    return res;
}
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  vector<ll> cnt(n, 0);

  ll res = 1;

  int r = 0;
  ll now = 1;

  for (int l = 0; l < n; l++) {
    while (r < n && now * a[r] < INF) {
      now *= a[r];
      r++;
    }
    int len = r - l;
    for (int i = l; i < r; i++) {
      cnt[i] += len;
      len--;
    }
    now /= a[l];
  }
  for (int i = 0; i < n; i++) {
    res *= mod_pow(a[i], cnt[i], mod);
    res %= mod;
  }
 
  cout << res << endl;
  return 0;
} 
0