結果
問題 | No.2580 Hyperinflation |
ユーザー | Kude |
提出日時 | 2023-12-08 13:58:57 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,091 bytes |
コンパイル時間 | 4,237 ms |
コンパイル使用メモリ | 295,672 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-27 02:48:55 |
合計ジャッジ時間 | 53,738 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
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 | 2 ms
5,376 KB |
testcase_04 | AC | 2 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 | 3 ms
5,376 KB |
testcase_14 | AC | 9 ms
5,376 KB |
testcase_15 | AC | 5 ms
5,376 KB |
testcase_16 | AC | 6 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 237 ms
5,376 KB |
testcase_19 | AC | 237 ms
5,376 KB |
testcase_20 | AC | 238 ms
5,376 KB |
testcase_21 | AC | 238 ms
5,376 KB |
testcase_22 | AC | 237 ms
5,376 KB |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
コンパイルメッセージ
main.cpp:106:14: warning: 'std::vector<{anonymous}::atcoder::static_modint<998244353> > {anonymous}::factorial2monomial(std::vector<atcoder::static_modint<998244353> >)' defined but not used [-Wunused-function] 106 | vector<mint> factorial2monomial(vector<mint> f) { | ^~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using mint = modint998244353; constexpr int FACT_SIZE = 3000; mint Fact[FACT_SIZE + 1]; mint iFact[FACT_SIZE + 1]; mint inv[FACT_SIZE + 1]; const auto fact_init = [] { Fact[0] = mint::raw(1); for(int i = 1; i <= FACT_SIZE; ++i) { Fact[i] = Fact[i-1] * i; } iFact[FACT_SIZE] = Fact[FACT_SIZE].inv(); for(int i = FACT_SIZE; i; --i) { iFact[i-1] = iFact[i] * i; } for (int i = 1; i <= FACT_SIZE; i++) { inv[i] = iFact[i] * Fact[i-1]; } return false; }(); vector<mint> fps_inverse(vector<mint> f, int precision) { int n = f.size(); assert(n >= 1 && f[0] != 0); int len = 1; const int z = bit_ceil(1U * precision); vector<mint> g{f[0].inv()}; const mint inv4 = mint(4).inv(); mint inv4k = 1; while (len < z) { int nlen = 2 * len; vector<mint> ft(f.begin(), f.begin() + min(n, nlen)); ft.resize(nlen); butterfly(ft); vector<mint> gt = g; gt.resize(nlen); internal::butterfly(gt); for (int i = 0; i < nlen; i++) ft[i] *= gt[i]; internal::butterfly_inv(ft); for (int i = 0; i < len; i++) ft[i] = mint(); internal::butterfly(ft); for (int i = 0; i < nlen; i++) ft[i] *= gt[i]; internal::butterfly_inv(ft); inv4k *= inv4; mint c = -inv4k; for (int i = len; i < nlen; i++) g.emplace_back(c * ft[i]); len = nlen; } g.resize(precision); return g; } vector<mint> monomial2factorial(vector<mint> f) { // a x = a P^-1 P x = a' P x // a' = a P^-1 int n = f.size(); if (n == 0) return f; vector<vector<mint>> prod(2 * n - 1); auto dfs1 = [&](auto&& self, int l, int r, int idx) { if (r - l == 1) { prod[idx] = {1, -l}; return; } int c = (l + r) / 2; self(self, l, c, idx + 1); self(self, c, r, idx + 2 * (c - l)); prod[idx] = convolution(prod[idx + 1], prod[idx + 2 * (c - l)]); }; dfs1(dfs1, 0, n, 0); ranges::reverse(f); f = convolution(f, fps_inverse(prod[0], n)); f.resize(n); auto dfs2 = [&](auto&& self, int l, int r, int idx) { if (r - l == 1) return; int c = (l + r) / 2; auto g = convolution(vector<mint>(f.begin() + n - r, f.begin() + n - l), prod[idx + 2 * (c - l)]); copy(g.begin() + r - c, g.begin() + r - l, f.begin() + n - c); self(self, l, c, idx + 1); self(self, c, r, idx + 2 * (c - l)); }; dfs2(dfs2, 0, n, 0); ranges::reverse(f); return f; } vector<mint> factorial2monomial(vector<mint> f) { // a x = a P^-1 P x = a' P x // a = a' P int n = f.size(); auto dfs = [&](auto&& self, int l, int r) { if (r - l == 1) return vector<mint>{-l, 1}; int c = (l + r) / 2; auto pl = self(self, l, c); auto pr = self(self, c, r); auto g = convolution(vector<mint>(f.begin() + c, f.begin() + r), pl); for (int i = l; i < c; i++) f[i] += g[i - l]; for (int i = c; i < r; i++) f[i] = g[i - l]; return l != 0 || r != n ? convolution(pl, pr) : vector<mint>{}; }; dfs(dfs, 0, n); return f; } vector<mint> factorial2monomial_shifted(vector<mint> f, mint shift) { // a x = a P^-1 P x = a' P x // a = a' P int n = f.size(); auto dfs = [&](auto&& self, int l, int r) { if (r - l == 1) return vector<mint>{-l + shift, 1}; int c = (l + r) / 2; auto pl = self(self, l, c); auto pr = self(self, c, r); auto g = convolution(vector<mint>(f.begin() + c, f.begin() + r), pl); for (int i = l; i < c; i++) f[i] += g[i - l]; for (int i = c; i < r; i++) f[i] = g[i - l]; return l != 0 || r != n ? convolution(pl, pr) : vector<mint>{}; }; dfs(dfs, 0, n); return f; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; VI a(n); rep(i, n - 1) cin >> a[i]; string m; cin >> m; for (char& c : m) c -= '0'; vector<mint> c(n); rep(i, n - 1) { unsigned int now = 0; rep(j, ssize(m)) { now = 10 * now + m[j]; m[j] = now / a[i]; now %= a[i]; } c[i] = now; } { mint now; for (char c : m) now = 10 * now + c; c[n - 1] = now; } vector<mint> f{1}; for (int i = 1; i < n; i++) { f = monomial2factorial(move(f)); f.insert(f.begin(), mint()); for (int j = 1; j <= i; j++) f[j] *= inv[j]; f = factorial2monomial_shifted(move(f), 1 + c[i]); mint aj = 1; rep(j, i + 1) { f[j] *= aj; aj *= a[i]; } } cout << f[0].val() << '\n'; }