結果

問題 No.1237 EXP Multiple!
ユーザー Takoyaki65Takoyaki65
提出日時 2020-10-09 15:57:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,966 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 94,800 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 12:42:39
合計ジャッジ時間 2,485 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;

template <class T>
inline int sz(T &x) {
    return x.size();
}

template <class T>
inline bool setmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool setmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

long long ll_pow(long long x, int n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res *= x;
        x *= x;
        n >>= 1;
    }
    return res;
}

long long factorial(long long x) {
    long long res = 1;
    while (x > 0) {
        res *= x;
        --x;
    }
    return res;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    repeat(i, N) cin >> A[i];
    int maxA = -10, minA = 1000000010;
    repeat(i, N) {
        setmax(maxA, A[i]);
        setmin(minA, A[i]);
    }
    //cout << maxA << endl;
    //cout << minA << endl;
    if (maxA >= 4) {
        cout << 1000000007 << endl;
    } else if (minA == 0) {
        cout << -1 << endl;
    } else {
        long long res = 1;
        repeat(i, N) {
            res *= ll_pow(A[i], factorial(A[i]));
            if (1000000007 <= res) {
                cout << 1000000007 << endl;
                return 0;
            }
        }
        cout << 1000000007 % res << endl;
    }
    return 0;
}
0