結果
問題 |
No.1084 積の積
|
ユーザー |
|
提出日時 | 2023-02-20 20:21:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 1,291 bytes |
コンパイル時間 | 626 ms |
コンパイル使用メモリ | 74,776 KB |
最終ジャッジ日時 | 2025-02-10 19:18:30 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 27 |
ソースコード
#include<iostream> #include<vector> using namespace std; using ll=long long; #define rep(i,n) for(int i=0;i<n;i++) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} const ll MOD=1e9+7,MAX=1e9-1; ll power(ll x,ll r){ ll re=1,k=x; for(int i=0;i<60;i++){ if(r>>i&1){ re=(re*k)%MOD; } k=k*k%MOD; } return re; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin>>N; vector<ll>A(N); rep(i,N)cin>>A[i]; rep(i,N){ if(A[i]==0){ cout<<0<<"\n"; return 0; } } vector<int>L(N); L[0]=0; ll pr=1; rep(i,N){ if(i>0)L[i]=min(N,L[i-1]); while(L[i]<N&&pr*A[L[i]]<=MAX){ pr*=A[L[i]]; L[i]++; } pr/=A[i]; } vector<ll>S(N+1); rep(i,N){ S[i]--; S[L[i]]++; } rrep(i,N)S[i]+=S[i+1]; rep(i,N)S[i]-=L[i]-i; rrep(i,N)S[i]+=S[i+1]; ll ans=1; rep(i,N)ans=ans*power(A[i],S[i+1])%MOD; cout<<ans<<"\n"; }