結果
問題 | No.2839 AND Constraint |
ユーザー | SnowBeenDiding |
提出日時 | 2024-08-10 00:41:04 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 23 ms / 2,000 ms |
コード長 | 5,842 bytes |
コンパイル時間 | 5,446 ms |
コンパイル使用メモリ | 319,716 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-08-10 00:41:11 |
合計ジャッジ時間 | 6,573 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 11 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 23 ms
6,940 KB |
testcase_07 | AC | 22 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 4 ms
6,940 KB |
testcase_11 | AC | 5 ms
6,940 KB |
testcase_12 | AC | 10 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 12 ms
6,944 KB |
testcase_15 | AC | 5 ms
6,940 KB |
testcase_16 | AC | 13 ms
6,940 KB |
testcase_17 | AC | 10 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 4 ms
6,940 KB |
ソースコード
#include <atcoder/all> #include <bits/stdc++.h> #define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++) using namespace atcoder; using namespace std; typedef long long ll; template <class T> struct FormalPowerSeries : vector<T> { using vector<T>::vector; using vector<T>::operator=; using F = FormalPowerSeries; F operator-() const { F res(*this); for (auto &e : res) e = -e; return res; } F &operator*=(const T &g) { for (auto &e : *this) e *= g; return *this; } F &operator/=(const T &g) { assert(g != T(0)); *this *= g.inv(); return *this; } F &operator+=(const F &g) { int n = (*this).size(), m = g.size(); for (int i = 0; i < min(n, m); i++) { (*this)[i] += g[i]; } return *this; } F &operator-=(const F &g) { int n = (*this).size(), m = g.size(); for (int i = 0; i < min(n, m); i++) { (*this)[i] -= g[i]; } return *this; } F &operator<<=(const int d) { int n = (*this).size(); (*this).insert((*this).begin(), d, 0); (*this).resize(n); return *this; } F &operator>>=(const int d) { int n = (*this).size(); (*this).erase((*this).begin(), (*this).begin() + min(n, d)); (*this).resize(n); return *this; } F inv(int d = -1) const { int n = (*this).size(); assert(n != 0 && (*this)[0] != 0); if (d == -1) d = n; assert(d > 0); F res{(*this)[0].inv()}; while (res.size() < d) { int m = size(res); F f(begin(*this), begin(*this) + min(n, 2 * m)); F r(res); f.resize(2 * m), internal::butterfly(f); r.resize(2 * m), internal::butterfly(r); for (int i = 0; i < 2 * m; i++) { f[i] *= r[i]; } internal::butterfly_inv(f); f.erase(f.begin(), f.begin() + m); f.resize(2 * m), internal::butterfly(f); for (int i = 0; i < 2 * m; i++) { f[i] *= r[i]; } internal::butterfly_inv(f); T iz = T(2 * m).inv(); iz *= -iz; for (int i = 0; i < m; i++) { f[i] *= iz; } res.insert(res.end(), f.begin(), f.begin() + m); } return {res.begin(), res.begin() + d}; } // fast: FMT-friendly modulus only F &operator*=(const F &g) { int n = (*this).size(); *this = convolution(*this, g); (*this).resize(n); return *this; } F &operator/=(const F &g) { int n = (*this).size(); *this = convolution(*this, g.inv(n)); (*this).resize(n); return *this; } // sparse F &operator*=(vector<pair<int, T>> g) { int n = (*this).size(); auto [d, c] = g.front(); if (d == 0) g.erase(g.begin()); else c = 0; for (int i = n - 1; i >= 0; i--) { (*this)[i] *= c; for (auto &[j, b] : g) { if (j > i) break; (*this)[i] += (*this)[i - j] * b; } } return *this; } F &operator/=(vector<pair<int, T>> g) { int n = (*this).size(); auto [d, c] = g.front(); assert(d == 0 && c != T(0)); T ic = c.inv(); g.erase(g.begin()); for (int i = 0; i < n; i++) { for (auto &[j, b] : g) { if (j > i) break; (*this)[i] -= (*this)[i - j] * b; } (*this)[i] *= ic; } return *this; } // multiply and divide (1 + cz^d) void multiply(const int d, const T c) { int n = (*this).size(); if (c == T(1)) for (int i = n - d - 1; i >= 0; i--) (*this)[i + d] += (*this)[i]; else if (c == T(-1)) for (int i = n - d - 1; i >= 0; i--) (*this)[i + d] -= (*this)[i]; else for (int i = n - d - 1; i >= 0; i--) (*this)[i + d] += (*this)[i] * c; } void divide(const int d, const T c) { int n = (*this).size(); if (c == T(1)) for (int i = 0; i < n - d; i++) (*this)[i + d] -= (*this)[i]; else if (c == T(-1)) for (int i = 0; i < n - d; i++) (*this)[i + d] += (*this)[i]; else for (int i = 0; i < n - d; i++) (*this)[i + d] -= (*this)[i] * c; } T eval(const T &a) const { T x(1), res(0); for (auto e : *this) res += e * x, x *= a; return res; } F operator*(const T &g) const { return F(*this) *= g; } F operator/(const T &g) const { return F(*this) /= g; } F operator+(const F &g) const { return F(*this) += g; } F operator-(const F &g) const { return F(*this) -= g; } F operator<<(const int d) const { return F(*this) <<= d; } F operator>>(const int d) const { return F(*this) >>= d; } F operator*(const F &g) const { return F(*this) *= g; } F operator/(const F &g) const { return F(*this) /= g; } F operator*(vector<pair<int, T>> g) const { return F(*this) *= g; } F operator/(vector<pair<int, T>> g) const { return F(*this) /= g; } }; using mint = modint998244353; using fps = FormalPowerSeries<mint>; using sfps = vector<pair<int, mint>>; int main() { int n, m; cin >> n >> m; vector<fps> dp(n + 1); dp[0] = fps(m + 1); dp[0][0] = 1; fps x = {0, 1}; rep(i, 0, n) { dp[i + 1] = dp[i]; dp[i + 1] += dp[i] * dp[i] * x; } cout << dp[n][m].val() << endl; }