結果

問題 No.3391 Line up Dominoes
コンテスト
ユーザー t98slider
提出日時 2025-11-28 21:55:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,347 ms / 3,000 ms
コード長 784 bytes
コンパイル時間 4,066 ms
コンパイル使用メモリ 255,644 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-11-28 21:56:59
合計ジャッジ時間 34,794 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n);
    for(auto &&v : a) cin >> v;
    sort(a.begin(), a.end());
    vector<mint> dp(n + 1, 1);
    dp[0] = 0;
    for(int i = 1; i < m; i++){
        for(int j = 0; j < n; j++) dp[j + 1] += dp[j];
        vector<mint> ndp(n + 1);
        for(int j = 0, l = 0, r = 0; j < n; j++){
            while(l < n && a[l] < a[j] - k) l++;
            while(r < n && a[r] <= a[j] + k) r++;
            ndp[j + 1] = dp[r] - dp[l];
        }
        swap(dp, ndp);
    }
    cout << accumulate(dp.begin(), dp.end(), mint::raw(0)).val() << '\n';
}
0