結果
問題 | No.1084 積の積 |
ユーザー |
![]() |
提出日時 | 2020-06-19 22:29:36 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 1,072 bytes |
コンパイル時間 | 1,460 ms |
コンパイル使用メモリ | 173,384 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-03 15:03:48 |
合計ジャッジ時間 | 3,009 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long int ll;typedef pair<ll, ll> P;typedef vector<ll> VI;typedef vector<VI> VVI;const ll MOD = 1000000007;const ll INF = 4611686018427387903;#define REP(i, n) for (int i = 0; i < n; i++)#define ALL(v) v.begin(), v.end()ll power(ll x, ll y) {if (y==0) return 1;else if (y==1) return x%MOD;else if (y%2==0) { ll pow=power(x,y/2); return (pow*pow)%MOD; }else { ll pow=power(x,y/2); return ((pow*pow)%MOD)*x%MOD; }}int main(){int n; cin >> n;VI a(n); REP(i,n) cin >> a[i];REP(i,n){if(a[i]==0){cout << 0 << endl;return 0;}}vector<P> b(0);REP(i,n){if(a[i]!=1)b.push_back({a[i],i});else if(i==n-1)b.push_back({a[i],i});}ll ans=1;REP(i,b.size()){ll p=b[i].second+1;if(i>0)p=b[i].second-b[i-1].second;ll c=1;for(int j=i;j<b.size();j++){c*=b[j].first;if(c>=1000000000)break;if(j<b.size()-1)ans*=power(c,(b[j+1].second-b[j].second)*p);elseans*=power(c,p);ans%=MOD;}}cout << ans << endl;return 0;}