結果

問題 No.3391 Line up Dominoes
コンテスト
ユーザー Tehom
提出日時 2025-11-28 23:13:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 781 ms / 3,000 ms
コード長 1,065 bytes
コンパイル時間 4,496 ms
コンパイル使用メモリ 257,888 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-11-28 23:14:01
合計ジャッジ時間 22,125 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repl(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a) (a).begin(),(a).end()

template <typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;} return false;}
template <typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;} return false;}

using mint=modint998244353;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  ll n,m,k; cin >> n >> m >> k;
  vector<ll> a(n);
  rep(i,0,n) cin >> a[i];
  vector<int> left(n),right(n);
  sort(all(a));
  rep(i,0,n){
    left[i]=lower_bound(all(a),a[i]-k)-a.begin();
    right[i]=upper_bound(all(a),a[i]+k)-a.begin();
  }
  vector<mint> dp(n+1);
  rep(i,0,n) dp[i]=1;
  vector<mint> c(n+1);
  rep(j,1,m){
    rep(i,0,n){
      c[left[i]]+=dp[i];
      c[right[i]]-=dp[i];
    }
    rep(i,0,n+1){
      dp[i]=c[i];
      c[i]=0;
    }
    rep(i,0,n) dp[i+1]+=dp[i];
  }
  mint ans=0;
  rep(i,0,n) ans+=dp[i];
  cout << ans.val() << endl;
}
0