結果

問題 No.1608 Yet Another Ants Problem
ユーザー merom686merom686
提出日時 2021-07-17 12:14:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,591 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 206,524 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-21 05:26:36
合計ジャッジ時間 4,680 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 26 ms
4,376 KB
testcase_15 AC 26 ms
4,376 KB
testcase_16 AC 26 ms
4,380 KB
testcase_17 AC 26 ms
4,376 KB
testcase_18 AC 26 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 12 ms
4,376 KB
testcase_21 AC 12 ms
4,380 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 25 ms
4,380 KB
testcase_24 AC 25 ms
4,380 KB
testcase_25 AC 26 ms
4,380 KB
testcase_26 AC 26 ms
4,380 KB
testcase_27 AC 25 ms
4,376 KB
testcase_28 AC 26 ms
4,376 KB
testcase_29 AC 26 ms
4,380 KB
testcase_30 AC 25 ms
4,380 KB
testcase_31 AC 25 ms
4,376 KB
testcase_32 AC 25 ms
4,376 KB
testcase_33 AC 24 ms
4,380 KB
testcase_34 AC 25 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

vector<mint> f0, f1;
void init(int n) {
    f0.resize(n + 1);
    f0[0] = 1;
    for (int i = 1; i <= n; i++) {
        f0[i] = f0[i - 1] * i;
    }
    f1.resize(n + 1);
    f1[n] = f0[n].inv();
    for (int i = n; i > 0; i--) {
        f1[i - 1] = f1[i] * i;
    }
}
mint fact(int k) {
    return f0[k];
}
mint comb(int n, int k) {
    if (n < k || k < 0) return 0;
    return f0[n] * f1[k] * f1[n - k];
}

int main() {
    int n, l;
    cin >> n >> l;

    init(n);

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<mint> r(n, 0);
    for (int j = 0; j < n; j++) {
        if (j < n - 1 && l - a[j + 1] > a[j]) continue;
        int y = lower_bound(a.begin(), a.begin() + j, l - a[j]) - a.begin();
        for (int i = 0; i < n; i++) {
            r[i] += comb(j - y, i - y);
            //cout << j - y << ' ' << i - y << endl;
        }
    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
        a[i] = l - a[i];
        //cout << a[i] << endl;
    }
    for (int j = 0; j < n; j++) {
        //cout << j << ' ' << l - a[j + 1] << ' ' << a[j] << endl;
        if (j < n - 1 && l - a[j + 1] >= a[j]) continue;
        int y = lower_bound(a.begin(), a.begin() + j, l - a[j] + 1) - a.begin();
        for (int i = 0; i < n; i++) {
            r[n - 1 - i] += comb(j - y, i - y);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << r[i].val() << '\n';
    }

    return 0;
}
0