結果

問題 No.2966 Simple Plus Minus Problem
ユーザー t98slidert98slider
提出日時 2024-11-16 17:03:33
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,587 bytes
コンパイル時間 5,051 ms
コンパイル使用メモリ 269,648 KB
実行使用メモリ 15,256 KB
最終ジャッジ日時 2024-11-16 17:04:10
合計ジャッジ時間 35,878 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    cin >> a;
    vector<mint> tmp(1, 1), coef(n), c(n);
    for(int i = 0; i < n; i += 2) coef[i] = 1;
    int ex = k / 2 + 1;
    while(ex != 0){
        if(ex & 1){
            tmp = convolution(tmp, coef);
            while(tmp.size() > n) tmp.pop_back();
        }
        coef = convolution(coef, coef);
        while(coef.size() > n) coef.pop_back();
        ex /= 2;
    }
    /*vector<int> d = {1, 0, 0};
    for(int i = 0; i < k; i++){
        for(int j = 1; j < n; j++){
            if (j % 2 == 1) d[j] = d[j - 1] - d[j];
            else d[j] = d[j - 1] + d[j];
        }
        cerr << d << '\n';
    }
    cerr << "\n";*/
    for(int i = 0; i < n; i++) c[i] = a[i];
    if(k % 2 == 1){
        for(int i = 1; i < n; i += 2){
            c[i] = -c[i];
            tmp[i] = tmp[i - 1];
        }
    }
    auto ans = convolution(c, tmp);
    while(ans.size() > n) ans.pop_back();
    for(int i = 0; i < n; i++){
        cout << ans[i].val() << (i + 1 == n ? '\n' : ' ');
    }
}
0