結果

問題 No.1608 Yet Another Ants Problem
ユーザー むかでむかで
提出日時 2021-06-08 12:51:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,593 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 79,988 KB
実行使用メモリ 38,944 KB
最終ジャッジ日時 2023-09-20 12:34:47
合計ジャッジ時間 3,517 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 93 ms
38,712 KB
testcase_15 AC 93 ms
38,620 KB
testcase_16 AC 93 ms
38,676 KB
testcase_17 AC 92 ms
38,620 KB
testcase_18 AC 93 ms
38,632 KB
testcase_19 AC 7 ms
6,184 KB
testcase_20 AC 38 ms
18,428 KB
testcase_21 AC 36 ms
17,904 KB
testcase_22 AC 22 ms
12,804 KB
testcase_23 AC 87 ms
37,272 KB
testcase_24 AC 79 ms
38,732 KB
testcase_25 AC 86 ms
38,636 KB
testcase_26 AC 86 ms
38,712 KB
testcase_27 AC 87 ms
38,816 KB
testcase_28 AC 86 ms
38,712 KB
testcase_29 AC 86 ms
38,712 KB
testcase_30 AC 53 ms
38,720 KB
testcase_31 AC 53 ms
38,944 KB
testcase_32 AC 54 ms
38,740 KB
testcase_33 AC 52 ms
38,668 KB
testcase_34 AC 53 ms
38,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using ll = long long;

constexpr int mod = 998244353;

vector<vector<int>> binom_table(int n){
    vector<vector<int>> ret(n, vector<int>(n));
    ret[0][0] = 1;
    for(int i=1; i<n; i++){
        for(int j=0; j<n; j++){
            ret[i][j] = ret[i-1][j];
            if (j > 0){
                ret[i][j] += ret[i-1][j-1];
                if (ret[i][j] >= mod) ret[i][j] -= mod;
            }
        }
    }
    return ret;
}

int main()
{
    int N,L; cin>>N>>L;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin>>A[i];

    auto binom = binom_table(N+1);

    vector<int> ans(N);
    ans[N-1]++;

    for(int lNum=0; lNum<N; lNum++){
        int rNum = N-lNum;
        int rVal = 0;

        int j = N;
        for(int i=0; i<=lNum; i++){
            while(j > 0 && A[j-1] >= L-A[i]) j--;

            if (j > i){
                if (rNum-1 >= N-j){
                    rVal += binom[N-i-1-(N-j)][rNum-1-(N-j)];
                    if (rVal >= mod) rVal -= mod;
                }
            }else if(j == i){
                if (rNum == N-j){
                    rVal = (rVal+1 < mod ? rVal+1 : 0);
                }
            }
        }

        int lVal = binom[N][lNum] - rVal;
        if (lVal < 0) lVal += mod;

        ans[lNum] += rVal;
        if (ans[lNum] >= mod) ans[lNum] -= mod;
        if (lNum > 0){
            ans[lNum-1] += lVal;
            if (ans[lNum-1] >= mod) ans[lNum-1] -= mod;
        }
    }

    for(int i=0; i<N; i++){
        cout<<ans[i]<<"\n";
    }
    return 0;
}
0