結果

問題 No.1237 EXP Multiple!
ユーザー KKT89
提出日時 2020-09-26 06:57:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 1,804 ms
コンパイル使用メモリ 200,168 KB
最終ジャッジ日時 2025-01-14 21:58:12
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

constexpr ll mod=1e9+7;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n);
	bool zero=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		if(!a[i])zero=true;
	}
	if(zero){
		printf("-1\n");
	}
	else{
		sort(a.rbegin(), a.rend());
		if(a[0]>=4){
			printf("%lld\n",mod);
		}
		else{
			ll res=1;
			for(int i=0;i<n;i++){
				if(a[i]==3){
					for(int j=0;j<6;j++){
						res*=a[i];
						if(res>mod){
							printf("%lld\n",mod);
							return 0;
						}
					}
				}
				else if(a[i]==2){
					for(int j=0;j<2;j++){
						res*=a[i];
						if(res>mod){
							printf("%lld\n",mod);
							return 0;
						}
					}
				}
			}
			printf("%lld\n",mod%res);
		}
	}
}
0