結果

問題 No.1084 積の積
ユーザー HaaHaa
提出日時 2020-06-19 22:20:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,061 bytes
コンパイル時間 1,458 ms
コンパイル使用メモリ 170,468 KB
実行使用メモリ 6,080 KB
最終ジャッジ日時 2023-09-16 14:38:38
合計ジャッジ時間 3,351 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,380 KB
testcase_04 WA -
testcase_05 AC 16 ms
4,376 KB
testcase_06 AC 15 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 36 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 18 ms
4,376 KB
testcase_13 AC 36 ms
5,764 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 14 ms
4,376 KB
testcase_16 AC 42 ms
5,896 KB
testcase_17 AC 17 ms
4,416 KB
testcase_18 AC 28 ms
4,752 KB
testcase_19 AC 37 ms
5,740 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 15 ms
4,376 KB
testcase_22 AC 11 ms
4,376 KB
testcase_23 AC 22 ms
4,416 KB
testcase_24 AC 21 ms
4,484 KB
testcase_25 AC 37 ms
5,884 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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=b[i].first;
		ans*=power(c,p); ans%=MOD;
		for(int j=i+1;j<b.size();j++){
			c*=b[j].first;
			if(c>1000000000)
				break;
			ans*=power(c,(b[j].second-b[j-1].second)*p);
			ans%=MOD;
		}
	}
	cout << ans << endl;
	return 0;
}
0