結果

問題 No.856 増える演算
ユーザー ミドリムシミドリムシ
提出日時 2019-07-26 22:31:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 303 ms / 3,153 ms
コード長 5,129 bytes
コンパイル時間 1,792 ms
コンパイル使用メモリ 173,980 KB
実行使用メモリ 14,400 KB
最終ジャッジ日時 2023-09-15 02:23:19
合計ジャッジ時間 17,235 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
13,512 KB
testcase_01 AC 94 ms
13,436 KB
testcase_02 AC 92 ms
13,520 KB
testcase_03 AC 92 ms
13,436 KB
testcase_04 AC 91 ms
13,480 KB
testcase_05 AC 92 ms
13,620 KB
testcase_06 AC 91 ms
13,428 KB
testcase_07 AC 91 ms
13,436 KB
testcase_08 AC 92 ms
13,516 KB
testcase_09 AC 92 ms
13,600 KB
testcase_10 AC 92 ms
13,488 KB
testcase_11 AC 92 ms
13,612 KB
testcase_12 AC 93 ms
13,444 KB
testcase_13 AC 91 ms
13,512 KB
testcase_14 AC 92 ms
13,500 KB
testcase_15 AC 92 ms
13,504 KB
testcase_16 AC 92 ms
13,556 KB
testcase_17 AC 91 ms
13,552 KB
testcase_18 AC 91 ms
13,620 KB
testcase_19 AC 91 ms
13,624 KB
testcase_20 AC 90 ms
13,516 KB
testcase_21 AC 91 ms
13,636 KB
testcase_22 AC 93 ms
13,760 KB
testcase_23 AC 96 ms
13,436 KB
testcase_24 AC 99 ms
13,608 KB
testcase_25 AC 93 ms
13,500 KB
testcase_26 AC 91 ms
13,612 KB
testcase_27 AC 92 ms
13,488 KB
testcase_28 AC 97 ms
13,608 KB
testcase_29 AC 94 ms
13,568 KB
testcase_30 AC 94 ms
13,604 KB
testcase_31 AC 92 ms
13,480 KB
testcase_32 AC 95 ms
13,440 KB
testcase_33 AC 104 ms
13,596 KB
testcase_34 AC 121 ms
13,868 KB
testcase_35 AC 110 ms
13,480 KB
testcase_36 AC 117 ms
13,736 KB
testcase_37 AC 113 ms
13,740 KB
testcase_38 AC 97 ms
13,608 KB
testcase_39 AC 97 ms
13,592 KB
testcase_40 AC 103 ms
13,516 KB
testcase_41 AC 103 ms
13,604 KB
testcase_42 AC 123 ms
13,856 KB
testcase_43 AC 101 ms
13,424 KB
testcase_44 AC 92 ms
13,608 KB
testcase_45 AC 96 ms
13,564 KB
testcase_46 AC 102 ms
13,428 KB
testcase_47 AC 99 ms
13,484 KB
testcase_48 AC 111 ms
13,884 KB
testcase_49 AC 105 ms
13,480 KB
testcase_50 AC 112 ms
13,752 KB
testcase_51 AC 117 ms
13,816 KB
testcase_52 AC 119 ms
13,748 KB
testcase_53 AC 229 ms
13,688 KB
testcase_54 AC 177 ms
13,872 KB
testcase_55 AC 227 ms
13,784 KB
testcase_56 AC 169 ms
13,876 KB
testcase_57 AC 236 ms
13,964 KB
testcase_58 AC 208 ms
13,820 KB
testcase_59 AC 272 ms
14,004 KB
testcase_60 AC 189 ms
13,872 KB
testcase_61 AC 276 ms
14,008 KB
testcase_62 AC 259 ms
13,964 KB
testcase_63 AC 107 ms
13,440 KB
testcase_64 AC 246 ms
14,132 KB
testcase_65 AC 158 ms
13,432 KB
testcase_66 AC 188 ms
13,744 KB
testcase_67 AC 216 ms
14,004 KB
testcase_68 AC 260 ms
13,956 KB
testcase_69 AC 255 ms
13,952 KB
testcase_70 AC 288 ms
14,292 KB
testcase_71 AC 261 ms
14,076 KB
testcase_72 AC 238 ms
14,008 KB
testcase_73 AC 301 ms
14,220 KB
testcase_74 AC 300 ms
14,232 KB
testcase_75 AC 301 ms
14,272 KB
testcase_76 AC 301 ms
14,360 KB
testcase_77 AC 302 ms
14,228 KB
testcase_78 AC 301 ms
14,400 KB
testcase_79 AC 301 ms
14,280 KB
testcase_80 AC 302 ms
14,292 KB
testcase_81 AC 303 ms
14,228 KB
testcase_82 AC 221 ms
14,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

namespace FastFourierTransform
{
    using C = complex< double >;
    
    void DiscreteFourierTransform(vector< C > &F, bool rev)
    {
        const int N = (int) F.size();
        const double PI = (rev ? -1 : 1) * acos(-1);
        for(int i = 0, j = 1; j + 1 < N; j++) {
            for(int k = N >> 1; k > (i ^= k); k >>= 1);
            if(i > j) swap(F[i], F[j]);
        }
        C w, s, t;
        for(int i = 1; i < N; i <<= 1) {
            for(int k = 0; k < i; k++) {
                w = polar(1.0, PI / i * k);
                for(int j = 0; j < N; j += i * 2) {
                    s = F[j + k];
                    t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(),
                          F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real());
                    F[j + k] = s + t, F[j + k + i] = s - t;
                }
            }
        }
        if(rev) for(int i = 0; i < N; i++) F[i] /= N;
    }
    
    vector< long long > Multiply(const vector< int > &A, const vector< int > &B)
    {
        int sz = 1;
        while(sz < A.size() + B.size() - 1) sz <<= 1;
        vector< C > F(sz), G(sz);
        for(int i = 0; i < A.size(); i++) F[i] = A[i];
        for(int i = 0; i < B.size(); i++) G[i] = B[i];
        DiscreteFourierTransform(F, false);
        DiscreteFourierTransform(G, false);
        for(int i = 0; i < sz; i++) F[i] *= G[i];
        DiscreteFourierTransform(F, true);
        vector< long long > X(A.size() + B.size() - 1);
        for(int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5;
        return (X);
    }
};

double make_log(lint Ai, lint Aj){
    return log(Ai) * Aj + log(Ai + Aj);
}

int main(){
    int N;
    cin >> N;
    lint A[N];
    cins(A, A + N);
    lint ans = 1;
    lint sum = 0;
    for(int i = N - 1; i >= 0; i--){
        ans = ans * power(A[i], sum, mod) % mod;
        sum += A[i];
    }
    vector<int> arr(1e5 + 100, 0);
    for(int i = 0; i < N; i++){
        arr[A[i]]++;
    }
    vector<lint> pairs = FastFourierTransform::Multiply(arr, arr);
    for(int i = 0; i < N; i++){
        pairs[A[i] * 2]--;
    }
    for(int i = 1; i < pairs.size(); i++){
        pairs[i] /= 2;
        ans = ans * power(i, pairs[i], mod) % mod;
    }
    lint minimum = min(A[N - 2], A[N - 1]);
    lint chosen_i = A[N - 2], chosen_j = A[N - 1];
    for(int i = N - 3; i >= 0; i--){
        if(make_log(A[i], minimum) < make_log(chosen_i, chosen_j)){
            chosen_i = A[i], chosen_j = minimum;
        }
        minimum = min(minimum, A[i]);
    }
    lint divide = (chosen_i + chosen_j) % mod * power(chosen_i, chosen_j, mod) % mod;
    ans = ans * power(divide, mod - 2, mod) % mod;
    cout << ans << endl;
}
0