結果

問題 No.2763 Macaron Gift Box
ユーザー pitPpitP
提出日時 2024-05-18 11:54:57
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,576 ms / 3,000 ms
コード長 7,487 bytes
コンパイル時間 6,387 ms
コンパイル使用メモリ 329,676 KB
実行使用メモリ 34,268 KB
最終ジャッジ日時 2024-05-18 11:55:14
合計ジャッジ時間 15,114 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 755 ms
18,308 KB
testcase_08 AC 174 ms
7,132 KB
testcase_09 AC 347 ms
10,904 KB
testcase_10 AC 1,535 ms
33,592 KB
testcase_11 AC 1,528 ms
34,184 KB
testcase_12 AC 1,576 ms
34,268 KB
testcase_13 AC 1,537 ms
34,136 KB
testcase_14 AC 191 ms
7,140 KB
testcase_15 AC 174 ms
7,252 KB
testcase_16 AC 171 ms
7,136 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); }
istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); }
istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } 

typedef long long ll;
typedef vector<vector<int>> Graph;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i,l,r) for (int i = l;i < (int)(r); i++)
#define rep(i,n) for (int i = 0;i < (int)(n); i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define my_sort(x) sort(x.begin(), x.end())
#define my_max(x) *max_element(all(x))
#define my_min(x) *min_element(all(x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;
const int MOD = 998244353;
const int MOD2 = 1e9+7;
const double PI = acos(-1);
vector<int> di = {1,0,-1,0};
vector<int> dj = {0,1,0,-1};

#ifdef LOCAL
#  include <debug_print.hpp>
#  define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define debug(...) (static_cast<void>(0))
#endif

// FFT
// https://trap.jp/post/1386/

// 原始根
// https://sen-comp.hatenablog.com/entry/2021/02/06/180310
using mint = modint998244353;

vector<mint> fft(vector<mint> A, mint root){
    const int N = A.size();
    if(N == 1) return A;

    vector<mint> even(N / 2), odd(N / 2);
    for(int i = 0; i < (N / 2); i++){
        even[i] = A[2 * i];
        odd[i] = A[2 * i + 1];
    }
    even = fft(even, root * root);
    odd = fft(odd, root * root);
    mint zeta = 1;
    for(int i = 0; i < (N / 2); i++){
        A[i] = even[i] + odd[i] * zeta;
        A[i + (N / 2)] = even[i] - odd[i] * zeta;
        zeta *= root;
    }
    return A;
}

vector<mint> ifft(vector<mint> A, mint iroot){
    const int N = A.size();
    if(N == 1) return A;

    vector<mint> even(N / 2), odd(N / 2);
    for(int i = 0; i < (N / 2); i++){
        even[i] = A[2 * i];
        odd[i] = A[2 * i + 1];
    }
    even = fft(even, iroot * iroot);
    odd = fft(odd, iroot * iroot);
    mint invN = 1 / mint(N);
    mint izeta = 1;
    for(int i = 0; i < (N / 2); i++){
        A[i] = (even[i] + odd[i] * izeta) * invN;
        A[i + (N / 2)] = (even[i] - odd[i] * izeta) * invN;
        izeta *= iroot;
    }
    return A;
}

// vector<mint> convolution(vector<mint> a, vector<mint> b){
//     int n = 1;
//     int m = a.size() + b.size() - 1;
//     while(n <= m) n <<= 1;
//     a.resize(n, 0);
//     b.resize(n, 0);
// 
//     mint root = mint(3).pow(998244352 / n);
//     vector<mint> A = fft(a, root);
//     vector<mint> B = fft(b, root);
//     for(int i = 0; i < n; i++) A[i] *= B[i];
// 
//     vector<mint> C = ifft(A, 1 / root);
//     C.resize(m);
//     return C;
// }

vector<mint> operator+(const vector<mint> &a, const vector<mint> &b){
    vector<mint> res(max((int)a.size(), (int)b.size()));
    for(int i = 0; i < (int)a.size(); i++) res[i] = res[i] + a[i];
    for(int i = 0; i < (int)b.size(); i++) res[i] = res[i] + b[i];
    return res;
}

vector<mint> operator+(mint constant, const vector<mint> &a){
    vector<mint> res((int)a.size());
    res[0] = constant;
    for(int i = 0; i < (int)a.size(); i++) res[i] = res[i] + a[i];
    return res;
}

vector<mint> operator+(const vector<mint> &a, mint constant){
    vector<mint> res((int)a.size());
    res[0] = constant;
    for(int i = 0; i < (int)a.size(); i++) res[i] = res[i] + a[i];
    return res;
}

vector<mint> operator-(const vector<mint> &a, const vector<mint> &b){
    vector<mint> res(max((int)a.size(), (int)b.size()));
    for(int i = 0; i < (int)a.size(); i++) res[i] = res[i] + a[i];
    for(int i = 0; i < (int)b.size(); i++) res[i] = res[i] - b[i];
    return res;
}

vector<mint> operator-(mint constant, const vector<mint> &a){
    vector<mint> res((int)a.size());
    res[0] = constant;
    for(int i = 0; i < (int)a.size(); i++) res[i] = res[i] - a[i];
    return res;
}

vector<mint> operator-(const vector<mint> &a, mint constant){
    vector<mint> res((int)a.size());
    for(int i = 0; i < (int)a.size(); i++) res[i] = a[i];
    res[0] = res[0] - constant;
    return res;
}

vector<mint> operator*(mint coef, const vector<mint> &a){
    vector<mint> res((int)a.size());
    for(int i = 0; i < (int)a.size(); i++) res[i] = a[i] * coef;
    return res;
}

vector<mint> operator*(const vector<mint> a, const vector<mint> b){
    return convolution(a, b);
}

// Library Chechker
vector<mint> fps_inv(vector<mint> a){
    int n = (int)a.size();
    int d = 1;
    vector<mint> g = {mint(a[0]).inv()};
    vector<mint> f = {a[0]};
    while(d < n){
        d <<= 1;
        g.resize(d, 0);
        while((int)f.size() < min(d, n)) f.push_back(a[(int)f.size()]);

        // g_{n+1} = 2 * g_n - f * g_n * g_n
        g = 2 * g - f * g * g;

        g.resize(d, 0);
    }
    return g;
}

vector<mint> operator/(const vector<mint> &a, const vector<mint> &b){
    return convolution(a, fps_inv(b));
}

vector<mint> operator/(mint constant, const vector<mint> &a){
    return constant * fps_inv(a);
}

vector<mint> operator/(const vector<mint> &a, mint constant){
    vector<mint> res((int)a.size());
    for(int i = 0; i < (int)a.size(); i++) res[i] = a[i] / constant;
    return res;
}

vector<mint> fps_diff(vector<mint> a){
    int n = (int)a.size();
    assert(n > 0);
    vector<mint> res(n, 0);
    for(int i = 0; i < n - 1; i++){
        res[i] = a[i + 1] * (mint)(i + 1);
    }
    return res;
}

vector<mint> fps_integral(vector<mint> a){
    int n = (int)a.size();
    assert(n > 0);
    vector<mint> res(n + 1, 0);
    for(int i = 1; i <= n; i++){
        res[i] = a[i - 1] / (mint)i;
    }
    return res;
}

// Library Checker
vector<mint> fps_log(vector<mint> a){
    assert(a[0] == 1);
    int n = (int)a.size();

    vector<mint> a_inv = fps_inv(a);
    vector<mint> a_diff = fps_diff(a);

    vector<mint> res = fps_integral(a_inv * a_diff);
    res.resize(n);
    return res;
}

// Library Checker
vector<mint> fps_exp(vector<mint> a){
    assert(a[0] == 0);
    int n = (int)a.size();
    int d = 1;

    vector<mint> g = {1};
    vector<mint> f = {a[0]};
    while(d < n){
        d <<= 1;
        g.resize(d, 0);
        while((int)f.size() < min(d, n)) f.push_back(a[(int)f.size()]);

        g = g * (1 - fps_log(g) + f);

        g.resize(d, 0);
    }
    return g;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll N, K; cin >> N >> K;

    vector<mint> invs(N + 1);
    FOR(v, 1, N + 1) invs[v] = mint(1) / mint(v);

    vector<mint> F(N + 1);
    for(ll j = 1; j <= N; j++){
        for(ll l = 1; l * (K + 1) * j <= N; l++){
            F[(K + 1) * j * l] -= invs[l];
        }
    }
    F = fps_exp(F);

    vector<mint> G(N + 1);
    for(ll j = 1; j <= N; j++){
        for(ll l = 1; l * j <= N; l++){
            G[j * l] -= invs[l];
        }
    }
    G = fps_exp(G);

    vector<mint> ans = F / G;
    FOR(X, 1, N + 1) cout << ans[X] << (X == N ? "\n" : " ");
}
0