結果

問題 No.1608 Yet Another Ants Problem
ユーザー milanis48663220milanis48663220
提出日時 2021-07-16 23:20:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,243 ms / 2,000 ms
コード長 2,944 bytes
コンパイル時間 3,757 ms
コンパイル使用メモリ 190,964 KB
実行使用メモリ 7,360 KB
最終ジャッジ日時 2024-06-10 01:06:37
合計ジャッジ時間 26,959 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
7,040 KB
testcase_01 AC 10 ms
7,004 KB
testcase_02 AC 9 ms
6,980 KB
testcase_03 AC 10 ms
7,168 KB
testcase_04 AC 10 ms
7,040 KB
testcase_05 AC 9 ms
7,004 KB
testcase_06 AC 9 ms
6,980 KB
testcase_07 AC 9 ms
7,040 KB
testcase_08 AC 9 ms
7,108 KB
testcase_09 AC 10 ms
6,984 KB
testcase_10 AC 9 ms
7,040 KB
testcase_11 AC 9 ms
7,040 KB
testcase_12 AC 10 ms
7,040 KB
testcase_13 AC 9 ms
7,004 KB
testcase_14 AC 1,221 ms
7,236 KB
testcase_15 AC 1,217 ms
7,360 KB
testcase_16 AC 1,232 ms
7,296 KB
testcase_17 AC 1,180 ms
7,240 KB
testcase_18 AC 1,206 ms
7,240 KB
testcase_19 AC 94 ms
7,296 KB
testcase_20 AC 428 ms
7,240 KB
testcase_21 AC 412 ms
7,296 KB
testcase_22 AC 295 ms
7,240 KB
testcase_23 AC 1,138 ms
7,236 KB
testcase_24 AC 1,218 ms
7,236 KB
testcase_25 AC 1,243 ms
7,296 KB
testcase_26 AC 1,194 ms
7,360 KB
testcase_27 AC 1,186 ms
7,296 KB
testcase_28 AC 1,192 ms
7,232 KB
testcase_29 AC 1,207 ms
7,296 KB
testcase_30 AC 1,202 ms
7,296 KB
testcase_31 AC 1,199 ms
7,296 KB
testcase_32 AC 1,191 ms
7,256 KB
testcase_33 AC 1,220 ms
7,296 KB
testcase_34 AC 1,193 ms
7,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#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-l+2), v(n-l+2);
        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