結果
問題 | No.2459 Stampaholic (Hard) |
ユーザー | Kude |
提出日時 | 2023-09-02 00:06:57 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 561 ms / 4,000 ms |
コード長 | 3,821 bytes |
コンパイル時間 | 3,460 ms |
コンパイル使用メモリ | 285,600 KB |
実行使用メモリ | 35,100 KB |
最終ジャッジ日時 | 2024-06-11 06:28:13 |
合計ジャッジ時間 | 10,530 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
11,336 KB |
testcase_01 | AC | 541 ms
34,968 KB |
testcase_02 | AC | 120 ms
16,260 KB |
testcase_03 | AC | 12 ms
11,212 KB |
testcase_04 | AC | 11 ms
11,336 KB |
testcase_05 | AC | 12 ms
11,336 KB |
testcase_06 | AC | 11 ms
11,328 KB |
testcase_07 | AC | 11 ms
11,340 KB |
testcase_08 | AC | 240 ms
21,108 KB |
testcase_09 | AC | 130 ms
16,688 KB |
testcase_10 | AC | 499 ms
33,096 KB |
testcase_11 | AC | 260 ms
22,776 KB |
testcase_12 | AC | 533 ms
34,716 KB |
testcase_13 | AC | 510 ms
32,968 KB |
testcase_14 | AC | 139 ms
17,116 KB |
testcase_15 | AC | 550 ms
34,968 KB |
testcase_16 | AC | 543 ms
35,100 KB |
testcase_17 | AC | 561 ms
35,092 KB |
testcase_18 | AC | 553 ms
35,096 KB |
testcase_19 | AC | 550 ms
35,092 KB |
testcase_20 | AC | 14 ms
11,336 KB |
testcase_21 | AC | 474 ms
31,544 KB |
コンパイルメッセージ
main.cpp:49:6: warning: '{anonymous}::mint {anonymous}::perm(int, int)' defined but not used [-Wunused-function] 49 | mint perm(int n, int k) { | ^~~~ main.cpp:48:6: warning: '{anonymous}::mint {anonymous}::fact(int)' defined but not used [-Wunused-function] 48 | mint fact(int n) {return Fact[n];} | ^~~~ main.cpp:44:6: warning: '{anonymous}::mint {anonymous}::icomb(int, int)' defined but not used [-Wunused-function] 44 | mint icomb(int n, int k) { | ^~~~~
ソースコード
#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 = 1000000; mint Fact[FACT_SIZE + 1]; mint iFact[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; } return false; }(); mint comb(int n, int k) { if (k == 0) return mint::raw(1); assert(n >= 0 && k >= 0); if (k > n) return mint::raw(0); return Fact[n] * iFact[n - k] * iFact[k]; } mint icomb(int n, int k) { return iFact[n] * Fact[n - k] * Fact[k]; } mint fact(int n) {return Fact[n];} mint perm(int n, int k) { assert(0 <= n); return Fact[n] * iFact[n - k]; } 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 = (int)std::bit_ceil((unsigned int)(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); internal::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); ft.erase(ft.begin(), ft.begin() + len); ft.resize(nlen); 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 = 0; i < len; i++) g.emplace_back(c * ft[i]); len = nlen; } g.resize(precision); return g; } vector<mint> kth_power_sums(mint n, int m) { // e^0+e^x+e^2x+...+e^(n-1)x // = ((e^nx-1)/x) / ((e^x-1)/x) // =: f / g // init_fact(m + 1); vector<mint> f(m), g(m); mint pow_n = n; for (int i = 0; i < m; i++) { f[i] = pow_n * iFact[i + 1]; g[i] = iFact[i + 1]; pow_n *= n; } vector<mint> res = convolution(f, fps_inverse(g, m)); res.resize(m); for (int i = 0; i < m; i++) res[i] *= Fact[i]; return res; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w, n, k; cin >> h >> w >> n >> k; int ubh = -1, ubw = -1; mint mxh = -1, mxw = -1; mint lh = -1, lw = -1; rep(_, 2) { if (h >= 2 * k) { ubh = k; mxh = k; lh = h - 2 * k + 2; } else { ubh = h - k + 1; mxh = h - k + 1; lh = 2 * k - h; } swap(h, w); swap(ubh, ubw); swap(mxh, mxw); swap(lh, lw); } mint tot = mint(h - k + 1) * (w - k + 1); auto ph = kth_power_sums(ubh, n + 1); auto pw = kth_power_sums(ubw, n + 1); ph[0]--; pw[0]--; mint ans; rep(i, n + 1) { mint coeff = comb(n, i) * tot.pow(n - i); if (i % 2) coeff *= -1; mint v; v += (mxh * mxw).pow(i) * lh * lw; v += mxh.pow(i) * lh * pw[i] * 2; v += ph[i] * mxw.pow(i) * lw * 2; v += ph[i] * pw[i] * 4; ans += coeff * v; } ans /= tot.pow(n); ans = mint(h) * w - ans; cout << ans.val() << '\n'; }