結果
問題 | No.856 増える演算 |
ユーザー | QCFium |
提出日時 | 2019-10-08 18:25:21 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,093 bytes |
コンパイル時間 | 2,006 ms |
コンパイル使用メモリ | 182,880 KB |
実行使用メモリ | 12,972 KB |
最終ジャッジ日時 | 2024-11-07 09:45:20 |
合計ジャッジ時間 | 16,078 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 110 ms
10,720 KB |
testcase_01 | AC | 110 ms
10,720 KB |
testcase_02 | AC | 112 ms
10,596 KB |
testcase_03 | AC | 111 ms
10,724 KB |
testcase_04 | AC | 111 ms
10,600 KB |
testcase_05 | AC | 112 ms
10,728 KB |
testcase_06 | AC | 111 ms
10,728 KB |
testcase_07 | AC | 111 ms
10,604 KB |
testcase_08 | AC | 111 ms
10,624 KB |
testcase_09 | AC | 113 ms
10,720 KB |
testcase_10 | AC | 112 ms
10,724 KB |
testcase_11 | AC | 112 ms
10,604 KB |
testcase_12 | AC | 113 ms
10,728 KB |
testcase_13 | AC | 114 ms
10,732 KB |
testcase_14 | AC | 112 ms
10,728 KB |
testcase_15 | AC | 113 ms
10,732 KB |
testcase_16 | AC | 112 ms
10,856 KB |
testcase_17 | AC | 113 ms
10,732 KB |
testcase_18 | AC | 112 ms
10,604 KB |
testcase_19 | AC | 112 ms
10,732 KB |
testcase_20 | AC | 113 ms
10,728 KB |
testcase_21 | AC | 113 ms
10,860 KB |
testcase_22 | AC | 111 ms
10,724 KB |
testcase_23 | AC | 113 ms
10,996 KB |
testcase_24 | AC | 115 ms
10,872 KB |
testcase_25 | AC | 114 ms
10,844 KB |
testcase_26 | AC | 110 ms
10,608 KB |
testcase_27 | AC | 109 ms
10,732 KB |
testcase_28 | AC | 116 ms
10,988 KB |
testcase_29 | AC | 114 ms
11,040 KB |
testcase_30 | AC | 114 ms
10,860 KB |
testcase_31 | AC | 113 ms
10,868 KB |
testcase_32 | AC | 115 ms
11,156 KB |
testcase_33 | AC | 119 ms
11,112 KB |
testcase_34 | AC | 131 ms
11,232 KB |
testcase_35 | AC | 122 ms
10,896 KB |
testcase_36 | AC | 130 ms
11,104 KB |
testcase_37 | AC | 127 ms
11,160 KB |
testcase_38 | AC | 113 ms
10,972 KB |
testcase_39 | AC | 115 ms
10,872 KB |
testcase_40 | AC | 119 ms
10,904 KB |
testcase_41 | AC | 118 ms
10,976 KB |
testcase_42 | AC | 134 ms
11,376 KB |
testcase_43 | AC | 120 ms
10,804 KB |
testcase_44 | AC | 113 ms
10,736 KB |
testcase_45 | AC | 114 ms
10,972 KB |
testcase_46 | AC | 119 ms
11,120 KB |
testcase_47 | AC | 116 ms
10,732 KB |
testcase_48 | AC | 124 ms
11,060 KB |
testcase_49 | AC | 119 ms
11,072 KB |
testcase_50 | AC | 126 ms
11,144 KB |
testcase_51 | AC | 131 ms
11,148 KB |
testcase_52 | AC | 132 ms
11,296 KB |
testcase_53 | AC | 169 ms
11,424 KB |
testcase_54 | AC | 142 ms
11,244 KB |
testcase_55 | AC | 168 ms
11,708 KB |
testcase_56 | AC | 140 ms
11,004 KB |
testcase_57 | AC | 172 ms
11,648 KB |
testcase_58 | AC | 158 ms
11,448 KB |
testcase_59 | AC | 195 ms
12,672 KB |
testcase_60 | AC | 146 ms
11,240 KB |
testcase_61 | AC | 196 ms
11,760 KB |
testcase_62 | AC | 187 ms
12,160 KB |
testcase_63 | AC | 117 ms
10,688 KB |
testcase_64 | AC | 177 ms
11,760 KB |
testcase_65 | AC | 134 ms
11,144 KB |
testcase_66 | AC | 145 ms
11,212 KB |
testcase_67 | AC | 162 ms
11,436 KB |
testcase_68 | AC | 187 ms
12,092 KB |
testcase_69 | AC | 184 ms
11,928 KB |
testcase_70 | AC | 209 ms
12,252 KB |
testcase_71 | AC | 190 ms
12,268 KB |
testcase_72 | AC | 178 ms
11,812 KB |
testcase_73 | AC | 229 ms
12,704 KB |
testcase_74 | AC | 219 ms
12,712 KB |
testcase_75 | AC | 225 ms
12,840 KB |
testcase_76 | AC | 224 ms
12,716 KB |
testcase_77 | AC | 225 ms
12,840 KB |
testcase_78 | WA | - |
testcase_79 | AC | 220 ms
12,840 KB |
testcase_80 | AC | 219 ms
12,844 KB |
testcase_81 | AC | 218 ms
12,840 KB |
testcase_82 | AC | 167 ms
12,716 KB |
ソースコード
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } int pow(int a, int b, int mod) { int res = 1; for (; b; b >>= 1) { if (b & 1) res = (int64_t) res * a % mod; a = (int64_t) a * a % mod; } return res; } int inv(int i, int mod) { return pow(i, mod - 2, mod); } template<int mod, int proot> struct NTT { int get_mod() { return mod; } void ntt(std::vector<int> &a, bool inverse) { int n = a.size(); assert((n & -n) == n); int h = pow(proot, (mod - 1) / n, mod); if (inverse) h = inv(h, mod); for (int i = 0, j = 1; j < n - 1; j++) { for (int k = n >> 1; k > (i ^= k); k >>= 1); if (j < i) std::swap(a[i], a[j]); } for (int i = 1; i < n; i <<= 1) { int base = pow(h, n / i / 2, mod); int w = 1; for (int j = 0; j < i; j++) { for (int k = j; k < n; k += i << 1) { int u = a[k]; int d = (int64_t) a[k + i] * w % mod; a[k] = u + d; if (a[k] >= mod) a[k] -= mod; a[k + i] = u - d; if (a[k + i] < 0) a[k + i] += mod; } w = (int64_t) w * base % mod; } } if (inverse) { int ninv = inv(a.size(), mod); for (auto &i : a) i = (int64_t) i * ninv % mod; } } std::vector<int> conv(const std::vector<int> a_, const std::vector<int> b_) { std::vector<int> a = a_, b = b_; size_t size = 1; for (; size < a_.size() + b_.size(); size <<= 1); a.resize(size); b.resize(size); ntt(a, false); ntt(b, false); for (size_t i = 0; i < size; i++) a[i] = (int64_t) a[i] * b[i] % mod; ntt(a, true); a.resize(a_.size() + b_.size() - 1); return a; } }; #define MOD 1000000007 std::vector<int64_t> conv(const std::vector<int> a, const std::vector<int> b) { NTT<998244353, 3> ntt1; NTT<469762049, 3> ntt2; auto r0 = ntt1.conv(a, b); auto r1 = ntt2.conv(a, b); int n = r0.size(); std::vector<int64_t> res; for (int i = 0; i < n; i++) { int64_t cur = r0[i]; while (cur % 469762049 != r1[i]) cur += 998244353; res.push_back(cur); } return res; } int main() { int n = ri(); int a[n]; for (int i = 0; i < n; i++) a[i] = ri(); std::multiset<std::pair<int, int> > all; for (int i = 0; i < n; i++) all.insert({a[i], i}); std::pair<int, int> optimal; double min = 1000000000; for (int i = 0; i + 1 < n; i++) { all.erase(all.find({a[i], i})); double cur = log2(a[i]) * all.begin()->first; if (min > cur) min = cur, optimal = {i, all.begin()->second}; } int64_t sum[n]; sum[n - 1] = 0; for (int i = n - 2; i >= 0; i--) sum[i] = sum[i + 1] + a[i + 1]; int res = 1; for (int i = 0; i < n; i++) res = (int64_t) res * pow(a[i], sum[i] % (MOD - 1), MOD) % MOD; std::vector<int> num(100001); for (int i = 0; i < n; i++) num[a[i]]++; auto conved = conv(num, num); for (int i = 0; i < n; i++) conved[a[i] + a[i]]--; for (int i = 1; i <= 200000; i++) assert(conved[i] % 2 == 0), conved[i] >>= 1, res = (int64_t) res * pow(i, conved[i] % (MOD - 1), MOD) % MOD; res = (int64_t) res * inv((int64_t) (a[optimal.first] + a[optimal.second]) * pow(a[optimal.first], a[optimal.second], MOD) % MOD, MOD) % MOD; std::cout << res << std::endl; return 0; }