結果

問題 No.1084 積の積
ユーザー HaaHaa
提出日時 2020-06-19 22:29:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,072 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 170,148 KB
実行使用メモリ 6,080 KB
最終ジャッジ日時 2023-09-16 14:45:00
合計ジャッジ時間 3,388 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 15 ms
4,376 KB
testcase_05 AC 15 ms
4,376 KB
testcase_06 AC 16 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 36 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 18 ms
4,380 KB
testcase_13 AC 37 ms
5,720 KB
testcase_14 AC 14 ms
4,380 KB
testcase_15 AC 13 ms
4,380 KB
testcase_16 AC 42 ms
5,820 KB
testcase_17 AC 17 ms
4,480 KB
testcase_18 AC 26 ms
4,692 KB
testcase_19 AC 37 ms
5,776 KB
testcase_20 AC 10 ms
4,380 KB
testcase_21 AC 14 ms
4,376 KB
testcase_22 AC 11 ms
4,380 KB
testcase_23 AC 23 ms
4,412 KB
testcase_24 AC 21 ms
4,436 KB
testcase_25 AC 37 ms
5,752 KB
testcase_26 AC 25 ms
5,896 KB
testcase_27 AC 24 ms
6,080 KB
testcase_28 AC 26 ms
5,808 KB
testcase_29 AC 25 ms
5,876 KB
testcase_30 AC 26 ms
5,900 KB
testcase_31 AC 26 ms
5,868 KB
権限があれば一括ダウンロードができます

ソースコード

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=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);
			else
				ans*=power(c,p);
			ans%=MOD;
		}
	}
	cout << ans << endl;
	return 0;
}
0