結果

問題 No.3391 Line up Dominoes
コンテスト
ユーザー ルビサファせだい
提出日時 2025-11-28 23:03:34
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 579 ms / 3,000 ms
コード長 1,509 bytes
コンパイル時間 3,545 ms
コンパイル使用メモリ 290,740 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-11-28 23:03:51
合計ジャッジ時間 16,263 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#include <atcoder/fenwicktree.hpp>
#include <atcoder/segtree.hpp>
#include <atcoder/modint.hpp>
#include <atcoder/dsu.hpp>
#include <atcoder/lazysegtree.hpp>

using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<>>;
ll ll_min = numeric_limits<ll>::min();
ll ll_max = numeric_limits<ll>::max();
ll ALPHABET_N = 26;
using mint = modint998244353;
// using mint = modint1000000007;
#define rep(i, n) for (ll i = (ll)0; i < (ll)n; i++)
#define rep_(i, k, n) for (ll i = (ll)k; i < (ll)n; i++)
#define all(a) a.begin(), a.end()
using i128 = __int128_t;

int main()
{
	ll n, m, k;
	cin >> n >> m >> k;
	vector<ll> A(n);
	rep(i, n) cin >> A[i];
	sort(all(A));
	vector<mint> dp(n, 1);
	vector<pair<ll, ll>> prs(n);
	rep(i, n)
	{
		ll s = lower_bound(all(A), A[i] - k) - A.begin();
		ll e = upper_bound(all(A), A[i] + k) - A.begin();
		prs[i] = {s, e};
	}
	rep(i, m - 1)
	{
		vector<mint> ndp(n, 0);
		ll l = 0, r = 0;
		rep(j, n)
		{
			// auto sit = lower_bound(all(A), A[j] - k);
			// auto eit = upper_bound(all(A), A[j] + k);
			// ll s = sit - A.begin(), e = eit - A.begin();
			auto [s, e] = prs.at(j);
			ndp[s] += dp[j];
			if (e < n)
				ndp[e] -= dp[j];
		}
		rep_(j, 1, n) ndp[j] = ndp[j - 1] + ndp[j];
		swap(dp, ndp);
	}
	mint ans = accumulate(all(dp), mint(0));
	cout << ans.val() << endl;
	return 0;
}
0