結果

問題 No.1084 積の積
ユーザー ateate
提出日時 2020-06-20 00:39:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 837 bytes
コンパイル時間 2,706 ms
コンパイル使用メモリ 197,328 KB
最終ジャッジ日時 2025-01-11 08:18:41
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1 RE * 1
other AC * 17 WA * 7 RE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = int64_t;
ll mod_pow(ll n,ll p,ll MOD){
  ll ans=1LL;
  while(p){
    if(p&1)ans*=n;
    n*=n;
    p>>=1;
    ans%=MOD;
    n%=MOD;
  }
  return ans;
}


signed main(){

  int n;
  cin>>n;
  vector a(n,0ll);
  for(auto& ai:a)cin>>ai;

  int64_t tmp = 1;
  const int64_t inf = 1e9;
  vector<int64_t> kl(n),kr(n);
  int l=0,r=0;
  for(;l<n;++l){
    while(r<n && tmp*a[r]<inf)tmp*=a[r++];
    kl[l] = r-l;
    tmp /= a[l];
  }
  reverse(begin(a),end(a));
  l=0,r=0;
  for(;l<n;++l){
    while(r<n && tmp*a[r]<inf)tmp*=a[r++];
    kr[l] = r-l;
    tmp /= a[l];
  }
  reverse(begin(kr),end(kr));
  reverse(begin(a),end(a));

  const int64_t MOD = 1e9+7;
  int64_t ans = 1;
  for(int i=0;i<n;++i){
    ans *= mod_pow(a[i],(kl[i]*kr[i]),MOD);
    ans %= MOD;
  }
  cout<<(ans)<<endl;


}
0