結果

問題 No.1237 EXP Multiple!
ユーザー hgotohgoto
提出日時 2020-10-28 15:20:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 724 bytes
コンパイル時間 2,642 ms
コンパイル使用メモリ 198,800 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 03:39:51
合計ジャッジ時間 4,020 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 17 ms
4,376 KB
testcase_02 AC 23 ms
4,380 KB
testcase_03 AC 23 ms
4,380 KB
testcase_04 AC 25 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 13 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 15 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 12 ms
4,380 KB
testcase_12 AC 15 ms
4,376 KB
testcase_13 AC 15 ms
4,376 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 15 ms
4,376 KB
testcase_16 AC 15 ms
4,380 KB
testcase_17 AC 15 ms
4,380 KB
testcase_18 AC 14 ms
4,380 KB
testcase_19 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

inline long long pow(long long a, long long r) {
  long long ret = 1;
  while (r--) ret *= a;
  return ret;
}

inline long long fact(long long a) {
  long long ret = a;
  while (--a) ret *= a;
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << -1 << '\n';
      return 0;
    }
  }
  long long ans = 1;
  const int md = (int)1e9 + 7;
  for (int i = 0; i < n; i++) {
    if (a[i] >= 4 || ans > md) {
      cout << md << '\n';
      return 0;
    }
    ans *= pow(a[i], fact(a[i]));
  }
  cout << md % ans << '\n';
  return 0;
}
0