結果
問題 | No.2763 Macaron Gift Box |
ユーザー |
|
提出日時 | 2024-05-17 22:11:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 111 ms / 3,000 ms |
コード長 | 2,528 bytes |
コンパイル時間 | 2,487 ms |
コンパイル使用メモリ | 116,036 KB |
実行使用メモリ | 11,284 KB |
最終ジャッジ日時 | 2024-12-20 14:03:35 |
合計ジャッジ時間 | 4,228 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 |
ソースコード
#include<iostream>#include<vector>#include<cassert>#include<atcoder/modint>#include<atcoder/convolution>using namespace std;//https://judge.yosupo.jp/submission/53740using Fp = atcoder::modint998244353;using Fps = std::vector<Fp>;int sz(const Fps& a) { return a.size(); }Fps operator-(Fps a) {for (auto&& e : a) e = -e;return a;}Fps& operator+=(Fps& a, const Fps& b) {if (sz(a) < sz(b)) a.reserve(sz(b)), a.resize(sz(b));for (int i = 0; i < sz(b); ++i) a[i] += b[i];return a;}Fps operator+(Fps a, const Fps& b) { return std::move(a += b); }Fps& operator-=(Fps& a, const Fps& b) {if (sz(a) < sz(b)) a.reserve(sz(b)), a.resize(sz(b));for (int i = 0; i < sz(b); ++i) a[i] -= b[i];return a;}Fps operator-(Fps a, const Fps& b) { return std::move(a -= b); }Fps& operator*=(Fps& a, Fp b) {for (auto&& e : a) e *= b;return a;}Fps operator*(Fps a, Fp b) { return std::move(a *= b); }Fps operator*(Fp a, Fps b) { return std::move(b *= a); }Fps& operator/=(Fps& a, Fp b) {b = b.inv();for (auto&& e : a) e *= b;return a;}Fps operator/(Fps a, Fp b) { return std::move(a /= b); }Fps operator*(const Fps& a, const Fps& b) {Fps res = atcoder::convolution(a, b);res.resize(std::max(sz(a), sz(b)));return res;}Fps& operator*=(Fps& a, const Fps& b) { return a = a * b; }Fps inv(const Fps& a) {Fps res{a[0].inv()};for (res.reserve(sz(a)); sz(res) < sz(a);) {Fps buf(2 * sz(res)), fres(sz(buf));std::copy(a.begin(), a.begin() + std::min(sz(buf), sz(a)), buf.begin());std::copy(res.begin(), res.end(), fres.begin());atcoder::internal::butterfly(buf);atcoder::internal::butterfly(fres);for (int i = 0; i < sz(buf); ++i) buf[i] *= fres[i];atcoder::internal::butterfly_inv(buf);std::fill(buf.begin(), buf.begin() + sz(res), 0);atcoder::internal::butterfly(buf);for (int i = 0; i < sz(buf); ++i) buf[i] *= fres[i];atcoder::internal::butterfly_inv(buf);Fp coeff = -Fp((1 - Fp::mod()) / sz(buf)).pow(2);for (int i = sz(res); i < std::min(sz(buf), sz(a)); ++i) res.push_back(buf[i] * coeff);}return res;}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int N,K;cin>>N>>K;Fps P(N+1,Fp::raw(0));P[0]=1;for(int n=1;n*(3*n-1)/2<=N;n++){P[n*(3*n-1)/2]+=n%2==0?1:-1;}for(int n=-1;n*(3*n-1)/2<=N;n--){P[n*(3*n-1)/2]+=n%2==0?1:-1;}Fps Q(N+1,Fp::raw(0));for(int i=0;i*(K+1)<=N;i++)Q[i*(K+1)]=P[i];Q*=inv(P);for(int i=1;i<=N;i++)cout<<Q[i].val()<<(i==N?"\n":" ");}