結果

問題 No.1084 積の積
ユーザー 👑 NachiaNachia
提出日時 2021-01-22 20:04:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 1,885 ms
コンパイル使用メモリ 198,592 KB
実行使用メモリ 4,492 KB
最終ジャッジ日時 2023-08-27 15:49:05
合計ジャッジ時間 4,593 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)


const ULL M = 1000000007;
ULL powm(ULL a,ULL i){ ULL r=1; while(i){ if(i%2) r=r*a%M; a=a*a%M; i/=2; } return r; }
ULL invm(ULL a){ return powm(a,M-2); }

int N;
ULL A[200000];

int main() {
  scanf("%d",&N); rep(i,N){ int a; scanf("%d",&a); A[i]=a; if(a==0){ printf("0\n"); return 0; } }
  int p=0; ULL prod=1, prodprod=1, ans=1;
  rep(q,N){
    prod*=A[q]; prodprod=prodprod*powm(A[q],q-p+1)%M;
    while(prod>=1000000000){ prodprod=prodprod*invm(prod%M)%M; prod/=A[p]; p++; }
    ans=ans*prodprod%M;
  }
  printf("%llu\n",ans);
  return 0;
}
0