結果

問題 No.1237 EXP Multiple!
ユーザー kyo1kyo1
提出日時 2020-10-11 17:04:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 200,144 KB
実行使用メモリ 4,752 KB
最終ジャッジ日時 2023-09-27 23:05:45
合計ジャッジ時間 4,027 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 18 ms
4,380 KB
testcase_02 AC 24 ms
4,532 KB
testcase_03 AC 24 ms
4,608 KB
testcase_04 AC 25 ms
4,752 KB
testcase_05 AC 3 ms
4,748 KB
testcase_06 AC 13 ms
4,752 KB
testcase_07 AC 3 ms
4,660 KB
testcase_08 AC 19 ms
4,564 KB
testcase_09 AC 3 ms
4,584 KB
testcase_10 AC 3 ms
4,540 KB
testcase_11 AC 13 ms
4,628 KB
testcase_12 AC 19 ms
4,556 KB
testcase_13 AC 20 ms
4,612 KB
testcase_14 AC 19 ms
4,612 KB
testcase_15 AC 20 ms
4,536 KB
testcase_16 AC 19 ms
4,676 KB
testcase_17 AC 20 ms
4,704 KB
testcase_18 AC 20 ms
4,624 KB
testcase_19 AC 13 ms
4,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int factorial(int x) {
  int res = 1;
  for (int i = 1; i < x + 1; i++) {
    res *= i;
  }
  return res;
}

template <typename T>
int64_t pow(int64_t x, T n, int64_t mod = std::numeric_limits<int64_t>::max()) {
  int64_t res = 1;
  while (n > 0) {
    if (n & 1) res = static_cast<__int128>(res) * static_cast<__int128>(x) % mod;
    x = static_cast<__int128>(x) * static_cast<__int128>(x) % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  const int MOD = 1000000007;
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (auto&& e : A) {
    cin >> e;
    if (e == 0) {
      cout << -1 << '\n';
      return 0;
    }
  }
  int64_t res = 1;
  for (int i = 0; i < N; i++) {
    int64_t a = A[i];
    if (a > 3) {
      cout << MOD << '\n';
      return 0;
    }
    res *= pow(a, factorial(a));
    if (res > MOD) {
      cout << MOD << '\n';
      return 0;
    }
  }
  cout << MOD % res << '\n';
  return 0;
}
0