結果

問題 No.2994 べき内積
ユーザー t98slider
提出日時 2024-12-21 05:53:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,358 bytes
コンパイル時間 4,260 ms
コンパイル使用メモリ 253,748 KB
最終ジャッジ日時 2025-02-26 16:01:34
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
using mint = atcoder::static_modint<1009>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n;
    cin >> m >> n;
    m++, n++;
    vector<int> K(m);
    vector<ll> A(n), B, ans(1, 1);
    for(auto &&v : K) cin >> v;
    for(auto &&v : A) cin >> v;
    int prd = 1, idx = 0;
    auto mul = [&](const vector<ll> &lhs, const vector<ll> &rhs){
        auto res = atcoder::convolution_ll(lhs, rhs);
        if(res.size() > n) res.resize(n);
        for(auto &&v : res) v %= 1009;
        return res;
    };
    auto frobenius = [&](int ex){
        vector<ll> tmp(1, 1);
        B = A;
        while(ex){
            if(ex & 1) tmp = mul(tmp, B);
            ex /= 2;
            if(ex) B = mul(B, B);
        }
        if(prd == 1009){
            vector<ll> res(1, tmp[0]);
            if(tmp.size() >= 2){
                res.resize(1010);
                res[1009] = tmp[1];
            }
            swap(res, tmp);
        }

        return tmp;
    };
    while(idx < m && prd < n){
        ans = mul(ans, frobenius(K[idx++]));
        prd *= 1009;
    }
    mint coef = mint::raw(A[0]).pow(accumulate(K.begin() + idx, K.end(), 0));
    for(int i = 0; i < n; i++){
        cout << (coef * ans[i]).val() << (i + 1 == n ? '\n' : ' ');
    }
}
0