結果
問題 | No.856 増える演算 |
ユーザー | ミドリムシ |
提出日時 | 2019-07-26 22:29:58 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,129 bytes |
コンパイル時間 | 1,515 ms |
コンパイル使用メモリ | 176,048 KB |
実行使用メモリ | 14,440 KB |
最終ジャッジ日時 | 2024-07-02 07:55:46 |
合計ジャッジ時間 | 14,998 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 84 ms
13,508 KB |
testcase_01 | AC | 84 ms
13,488 KB |
testcase_02 | AC | 83 ms
13,664 KB |
testcase_03 | AC | 85 ms
13,660 KB |
testcase_04 | AC | 87 ms
13,452 KB |
testcase_05 | AC | 85 ms
13,448 KB |
testcase_06 | AC | 82 ms
13,488 KB |
testcase_07 | AC | 83 ms
13,576 KB |
testcase_08 | AC | 88 ms
13,524 KB |
testcase_09 | WA | - |
testcase_10 | AC | 84 ms
13,524 KB |
testcase_11 | AC | 82 ms
13,488 KB |
testcase_12 | AC | 87 ms
13,548 KB |
testcase_13 | AC | 84 ms
13,528 KB |
testcase_14 | AC | 84 ms
13,484 KB |
testcase_15 | AC | 81 ms
13,464 KB |
testcase_16 | AC | 83 ms
13,488 KB |
testcase_17 | AC | 83 ms
13,548 KB |
testcase_18 | AC | 82 ms
13,580 KB |
testcase_19 | AC | 83 ms
13,604 KB |
testcase_20 | WA | - |
testcase_21 | AC | 85 ms
13,468 KB |
testcase_22 | AC | 84 ms
13,548 KB |
testcase_23 | AC | 85 ms
13,564 KB |
testcase_24 | AC | 91 ms
13,652 KB |
testcase_25 | AC | 86 ms
13,520 KB |
testcase_26 | AC | 83 ms
13,552 KB |
testcase_27 | AC | 81 ms
13,456 KB |
testcase_28 | AC | 88 ms
13,564 KB |
testcase_29 | AC | 88 ms
13,700 KB |
testcase_30 | AC | 85 ms
13,604 KB |
testcase_31 | AC | 85 ms
13,616 KB |
testcase_32 | AC | 89 ms
13,656 KB |
testcase_33 | AC | 94 ms
13,552 KB |
testcase_34 | AC | 109 ms
13,708 KB |
testcase_35 | AC | 100 ms
13,732 KB |
testcase_36 | AC | 107 ms
13,680 KB |
testcase_37 | AC | 105 ms
13,720 KB |
testcase_38 | AC | 86 ms
13,524 KB |
testcase_39 | AC | 90 ms
13,616 KB |
testcase_40 | AC | 90 ms
13,540 KB |
testcase_41 | AC | 94 ms
13,596 KB |
testcase_42 | AC | 107 ms
13,716 KB |
testcase_43 | AC | 96 ms
13,600 KB |
testcase_44 | AC | 86 ms
13,460 KB |
testcase_45 | AC | 88 ms
13,484 KB |
testcase_46 | AC | 94 ms
13,548 KB |
testcase_47 | AC | 91 ms
13,676 KB |
testcase_48 | AC | 98 ms
13,660 KB |
testcase_49 | AC | 96 ms
13,576 KB |
testcase_50 | AC | 97 ms
13,620 KB |
testcase_51 | AC | 104 ms
13,660 KB |
testcase_52 | AC | 110 ms
13,828 KB |
testcase_53 | AC | 210 ms
13,864 KB |
testcase_54 | AC | 162 ms
13,840 KB |
testcase_55 | AC | 205 ms
13,872 KB |
testcase_56 | AC | 152 ms
13,684 KB |
testcase_57 | AC | 219 ms
13,880 KB |
testcase_58 | AC | 184 ms
13,828 KB |
testcase_59 | AC | 245 ms
14,076 KB |
testcase_60 | AC | 171 ms
13,684 KB |
testcase_61 | AC | 250 ms
14,248 KB |
testcase_62 | AC | 229 ms
14,120 KB |
testcase_63 | AC | 98 ms
13,592 KB |
testcase_64 | AC | 228 ms
14,040 KB |
testcase_65 | AC | 147 ms
13,700 KB |
testcase_66 | AC | 164 ms
13,856 KB |
testcase_67 | AC | 197 ms
13,900 KB |
testcase_68 | AC | 235 ms
14,004 KB |
testcase_69 | AC | 227 ms
13,996 KB |
testcase_70 | AC | 263 ms
14,304 KB |
testcase_71 | AC | 238 ms
14,172 KB |
testcase_72 | AC | 215 ms
13,912 KB |
testcase_73 | AC | 269 ms
14,240 KB |
testcase_74 | AC | 269 ms
14,236 KB |
testcase_75 | AC | 278 ms
14,228 KB |
testcase_76 | AC | 276 ms
14,324 KB |
testcase_77 | AC | 269 ms
14,300 KB |
testcase_78 | AC | 277 ms
14,256 KB |
testcase_79 | AC | 268 ms
14,320 KB |
testcase_80 | AC | 268 ms
14,380 KB |
testcase_81 | AC | 268 ms
14,328 KB |
testcase_82 | AC | 191 ms
14,440 KB |
ソースコード
#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 - 2; 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; }