結果

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

ソースコード

diff #

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

long long intpow(long long a, long long b){ 
    long long ans = 1; 
    while(b){ 
        if(b & 1) ans *= a; 
        a *= a; 
        b >>= 1; 
    } 
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int m, n;
    cin >> m >> n;
    m++, n++;
    vector<int> K(m), A(n);
    for(auto &&v : K) cin >> v;
    for(auto &&v : A) cin >> v;
    vector<mint> ans(1, 1), B(n);
    int prd = 1, idx = 0;
    auto safe = [&](vector<mint> &tmp){ for(auto &&v : tmp) v = mint::raw(v.val() % 1009); };
    auto frobenius = [&](int ex){
        vector<mint> tmp(1, 1);
        for(int i = 0; i < n; i++) B[i] = mint::raw(A[i]);
        while(ex){
            if(ex & 1){
                (tmp = convolution(tmp, B)).resize(n);
                safe(tmp);
            }
            ex /= 2;
            if(ex){
                (B = convolution(B, B)).resize(n);
                safe(B);
            }
        }
        if(prd == 1009){
            vector<mint> 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 = convolution(ans, frobenius(K[idx++]))).resize(n);
        safe(ans);
        prd *= 1009;
    }
    mint2 coef = mint2::raw(A[0]).pow(accumulate(K.begin() + idx, K.end(), 0));
    for(int i = 0; i < n; i++){
        cout << (coef * ans[i].val()).val() << (i + 1 == n ? '\n' : ' ');
    }
}
0