結果
問題 | No.1237 EXP Multiple! |
ユーザー |
|
提出日時 | 2020-11-27 13:37:24 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 961 bytes |
コンパイル時間 | 1,729 ms |
コンパイル使用メモリ | 170,136 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-23 21:35:32 |
合計ジャッジ時間 | 3,318 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define ll long long // a!を計算する ll fact(int a){ if (a == 0) return 1LL; return a * fact(a - 1); } // a^bを計算する ll powInt(int a, int b){ if (b == 0) return 1LL; ll tmp = powInt(a, b / 2); tmp *= tmp; if (b % 2) return tmp * a; return tmp; } // a^(a!)を計算する ll calc(int a){ int f = fact(a); return powInt(a, f); } int N; vector<int> A; void input(void){ cin >> N; A.resize(N); for (int& ai : A) cin >> ai; } ll solve(void){ bool zeroExist = false; for (int ai : A) zeroExist |= (ai == 0); if (zeroExist) return -1LL; ll ans = 1LL; for (int ai : A){ if (ai >= 4) return 1000000007LL; ans *= calc(ai); if (ans >= 1000000007LL) return 1000000007LL; } return (1000000007LL % ans); } int main(void){ input(); cout << solve() << endl; return 0; }