結果

問題 No.1084 積の積
ユーザー 👑 Nachia
提出日時 2021-01-22 20:04:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 2,565 ms
コンパイル使用メモリ 191,940 KB
最終ジャッジ日時 2025-01-18 03:31:14
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |   scanf("%d",&N); rep(i,N){ int a; scanf("%d",&a); A[i]=a; if(a==0){ printf("0\n"); return 0; } }
      |   ~~~~~^~~~~~~~~
main.cpp:16:41: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |   scanf("%d",&N); rep(i,N){ int a; scanf("%d",&a); A[i]=a; if(a==0){ printf("0\n"); return 0; } }
      |                                    ~~~~~^~~~~~~~~

ソースコード

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