結果
問題 | No.444 旨味の相乗効果 |
ユーザー | Min_25 |
提出日時 | 2016-11-12 01:55:47 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,500 ms |
コード長 | 3,536 bytes |
コンパイル時間 | 1,930 ms |
コンパイル使用メモリ | 111,404 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-24 20:53:58 |
合計ジャッジ時間 | 2,592 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 3 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 2 ms
5,376 KB |
testcase_27 | AC | 2 ms
5,376 KB |
ソースコード
#pragma GCC optimize ("O3") #pragma GCC target ("avx") #include <cstdio> #include <cassert> #include <cmath> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <map> #include <set> #include <functional> #include <stack> #include <queue> #include <tuple> #define getchar getchar_unlocked #define putchar putchar_unlocked #define _rep(_1, _2, _3, _4, name, ...) name #define rep2(i, n) rep3(i, 0, n) #define rep3(i, a, b) rep4(i, a, b, 1) #define rep4(i, a, b, c) for (int i = int(a); i < int(b); i += int(c)) #define rep(...) _rep(__VA_ARGS__, rep4, rep3, rep2, _)(__VA_ARGS__) using namespace std; using i8 = signed char; using i16 = signed short; using i64 = long long; using u8 = unsigned char; using u32 = unsigned; using u64 = unsigned long long; using f80 = long double; namespace poly_light { using R = int; using poly = vector<R>; vector<i64> tmp64; R mod; i64 lmod; R mul_mod(R a, R b) { return i64(a) * b % mod; } i64 add_mod64(i64 a, i64 b) { return (a += b - lmod) < 0 ? a + lmod : a; } i64 sub_mod64(i64 a, i64 b) { return (a -= b) < 0 ? a + lmod : a; } R fixed(R a) { return (a %= mod) < 0 ? a + mod : a; } void set_mod(R m) { mod = m; lmod = i64(mod) << 32; } poly poly_mul(const poly& f, const poly& g) { int s1 = f.size(), s2 = g.size(), s = s1 + s2 - 1; tmp64.assign(s, 0); rep(i, s1) if (f[i]) rep(j, s2) { tmp64[i + j] = add_mod64(tmp64[i + j], i64(f[i]) * g[j]); } poly ret(s); rep(i, s) ret[i] = tmp64[i] % mod; return ret; } poly poly_rem(const poly& f, const poly& g) { int s1 = f.size(), s2 = g.size(); if (s1 < s2) return f; assert(g[0] == 1); tmp64.resize(s1); copy(f.begin(), f.end(), tmp64.begin()); rep(i, s1 - s2 + 1) { int c = tmp64[i] % mod; if (c) rep(j, 1, s2) tmp64[i + j] = sub_mod64(tmp64[i + j], i64(c) * g[j]); tmp64[i] = c; } poly ret(s2 - 1); rep(i, s2 - 1) ret[i] = tmp64[s1 - s2 + 1 + i] % mod; return ret; } poly x_pow_mod(i64 e, const poly& f) { if (e == 0) return poly(1, 1); poly ret = poly_rem(poly({1, 0}), f); for (i64 mask = (i64(1) << __lg(e) >> 1); mask; mask >>= 1) { ret = poly_mul(ret, ret); if (e & mask) ret.push_back(0); ret = poly_rem(ret, f); } return ret; } R nth_term(i64 e, poly f, poly terms, const R mod) { if (mod == 1) return 0; assert(f.size() >= terms.size() + 1); set_mod(mod); rep(i, f.size()) f[i] = fixed(f[i]); rep(i, terms.size()) terms[i] = fixed(terms[i]); auto rem = x_pow_mod(e, f); reverse(rem.begin(), rem.end()); i64 ret = 0; rep(i, rem.size()) ret = add_mod64(ret, i64(rem[i]) * terms[i]); return ret % mod; } } // poly_light void solve() { const int mod = 1e9 + 7; poly_light::set_mod(mod); auto pow_mod = [&] (int b, i64 e) { int ret = 1; for (; e; e >>= 1, b = i64(b) * b % mod) if (e & 1) ret = i64(ret) * b % mod; return ret; }; int A[128], sum[128]; int n; i64 c; while (~scanf("%d %lld", &n, &c)) { poly_light::poly f(1, 1), terms(n, 0); int ans = 0; rep(i, n) { scanf("%d", &A[i]); f = poly_light::poly_mul(f, {1, (mod - A[i]) % mod}); sum[i] = A[i]; ans = (ans + pow_mod(A[i], c)) % mod; } rep(i, n) rep(j, n) (terms[i] += sum[j]) %= mod, sum[j] = (i64(terms[i]) * A[j]) % mod; ans = (mod - ans + poly_light::nth_term(c - 1, f, terms, mod)) % mod; printf("%d\n", ans); } } int main() { auto beg = clock(); solve(); auto end = clock(); fprintf(stderr, "%.3f sec\n", double(end - beg) / CLOCKS_PER_SEC); }