結果

問題 No.1608 Yet Another Ants Problem
ユーザー milanis48663220milanis48663220
提出日時 2021-07-16 23:15:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,848 bytes
コンパイル時間 2,785 ms
コンパイル使用メモリ 159,336 KB
実行使用メモリ 11,580 KB
最終ジャッジ日時 2023-09-20 15:43:36
合計ジャッジ時間 6,712 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
7,276 KB
testcase_01 AC 12 ms
6,984 KB
testcase_02 AC 12 ms
7,220 KB
testcase_03 AC 12 ms
6,984 KB
testcase_04 AC 12 ms
7,044 KB
testcase_05 AC 12 ms
7,136 KB
testcase_06 AC 12 ms
7,004 KB
testcase_07 AC 12 ms
7,220 KB
testcase_08 AC 12 ms
7,132 KB
testcase_09 AC 12 ms
6,992 KB
testcase_10 AC 12 ms
6,984 KB
testcase_11 AC 12 ms
6,916 KB
testcase_12 AC 12 ms
6,996 KB
testcase_13 AC 12 ms
6,936 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/modint>
#include <atcoder/convolution>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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; }

using namespace std;
typedef long long ll;

const ll MOD = 998244353;
using mint = atcoder::modint998244353;


#define N_MAX 300002
mint inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=1;fac[1]=1;
    finv[0]=1;finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=mint(MOD)-inv[MOD%i]*(MOD/i);
        fac[i]=fac[i-1]*(ll) i;
        finv[i]=finv[i-1]*inv[i];
    }
}

mint pow(mint a, ll n) {
    assert(n >= 0);
	mint res = 1;
	
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
	return res;
}

/**
 * a0+a1*(x+c)^1+ ... + an*(x+c)^nの係数を求める
 */ 
vector<mint> slide_polynomial(vector<mint> a, int c){
    int n = a.size();
    vector<mint> u(n), v(n);
    for(int i = 0; i < n; i++) {
        u[i] = a[i]*fac[i];
        v[i] = pow(mint(c), n-i-1)*finv[n-i-1];
    }
    auto w = atcoder::convolution(u, v);
    vector<mint> ans(n);
    for(int i = 0; i < n; i++) ans[i] = finv[i]*w[i+n-1];
    return ans;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    int n, L; cin >> n >> L;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++) cin >> a[i];
    vector<mint> ans(n+1);
    for(int l = 1; l <= n; l++){
        vector<mint> u(n+1), v(n+1);
        for(int r = l+1; r <= n; r++){
            int x = r-l-1;
            if(L-a[l] > a[r]){ // lがlast
                u[x] += 1;
            }else{ // rがlast
                v[x] += 1;
            }
        }
        // cout << "=====" << endl;
        // for(auto a: u) cout << a.val() << ' ';
        // cout << endl;
        // for(auto a: v) cout << a.val() << ' ';
        // cout << endl;
        auto us = slide_polynomial(u, 1);
        for(int i = 0; i+l+1 <= n; i++) ans[i+l+1] += us[i];
        auto vs = slide_polynomial(v, 1);
        for(int i = 0; i+l <= n; i++) ans[i+l] += vs[i];
    }
    // 全部左
    ans[n]+=1;
    // 全部右
    ans[1]+=1;
    for(int i = 1; i < n; i++){
        if(a[i] >= L-a[i+1]){
            ans[i] += 1;
        }else{
            ans[i+1] += 1;
        }
    }
    for(int i = 1; i <= n; i++) cout << ans[i].val() << endl;
}
0