結果

問題 No.1608 Yet Another Ants Problem
ユーザー むかでむかで
提出日時 2021-06-08 14:44:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,354 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 81,156 KB
実行使用メモリ 38,936 KB
最終ジャッジ日時 2023-09-20 12:34:50
合計ジャッジ時間 2,937 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 50 ms
38,812 KB
testcase_15 AC 50 ms
38,672 KB
testcase_16 AC 50 ms
38,704 KB
testcase_17 AC 51 ms
38,672 KB
testcase_18 AC 50 ms
38,688 KB
testcase_19 AC 5 ms
6,240 KB
testcase_20 AC 22 ms
18,408 KB
testcase_21 AC 21 ms
17,868 KB
testcase_22 AC 15 ms
12,804 KB
testcase_23 AC 49 ms
37,312 KB
testcase_24 AC 50 ms
38,808 KB
testcase_25 AC 53 ms
38,936 KB
testcase_26 AC 54 ms
38,684 KB
testcase_27 AC 54 ms
38,796 KB
testcase_28 AC 54 ms
38,684 KB
testcase_29 AC 53 ms
38,732 KB
testcase_30 AC 47 ms
38,796 KB
testcase_31 AC 47 ms
38,808 KB
testcase_32 AC 46 ms
38,732 KB
testcase_33 AC 46 ms
38,936 KB
testcase_34 AC 46 ms
38,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;
using ll = long long;

constexpr int mod = 998244353;

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

    vector<vector<int>> dp(N+1, vector<int>(N+1));
    dp[1][0] = 1;
    for(int i=2; i<=N; i++){
        for(int j=0; j<=N; j++){
            if (j == 0){
                dp[i][j] = (dp[i-1][j]+1 < mod ? dp[i-1][j]+1 : 0);
            }else{
                dp[i][j] = dp[i-1][j] + dp[i-1][j-1];
                if (dp[i][j] >= mod) dp[i][j] -= mod;
            }
        }
    }

    vector<int> ans(N);
    
    ans[0]++; ans[N-1]++;
    for(int i=0; i<N-1; i++){
        if (A[i] >= L-A[i+1]) ans[i]++;
        else ans[i+1]++;
    }

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

        for(int k=i+1, l=0; k<j; k++, l++){
            ans[k] += dp[j-i-1][l];
            if (ans[k] >= mod) ans[k] -= mod;
        }

        for(int k=i, l=0; k<N-1; k++, l++){
            ans[k] += dp[N-i-1][l];
            if (ans[k] >= mod) ans[k] -= mod;
        }
        for(int k=i, l=0; k<j-1; k++, l++){
            ans[k] -= dp[j-i-1][l];
            if (ans[k] < 0) ans[k] += mod;
        }
    }

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

    return 0;
}
0