結果

問題 No.3166 [Cherry 7th Tune *] 桜の守人
ユーザー shobonvip
提出日時 2025-05-30 21:46:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 286 ms / 2,000 ms
コード長 2,370 bytes
コンパイル時間 4,263 ms
コンパイル使用メモリ 255,348 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-05-30 21:46:27
合計ジャッジ時間 10,943 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
	author:  shobonvip
	created: 2025.05.30 21:19:26
**/

#include<bits/stdc++.h>
using namespace std;

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)
#define all(v) v.begin(), v.end()

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

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

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

void solve() {
	int n; cin >> n;
	ll l; cin >> l;
	int k; cin >> k;
	vector<ll> x(n);
	rep(i,0,n) cin >> x[i];

	auto check = [&] (ll t) -> bool {
		if (2*t >= l) return true;
		vector<ll> val;
		rep(i,0,n) {
			ll lft = x[i] - t;
			ll rgt = x[i] + t;
			val.push_back((lft % l + l) % l);
			val.push_back((rgt % l + l) % l);
		}
		val.push_back(0);
		val.push_back(l);
		sort(all(val));
		val.erase(unique(all(val)),val.end());

		int m = (int)val.size();
		vector<ll> imos(m);

		rep(i,0,n) {
			ll lft = x[i] - t;
			ll rgt = x[i] + t;
			lft = (lft % l + l) % l;
			rgt = (rgt % l + l) % l;
			int lt = int(lower_bound(all(val),lft)-val.begin());
			int rt = int(lower_bound(all(val),rgt)-val.begin());
			if (lt < rt) {
				imos[lt] += 1;
				imos[rt] -= 1;
			}else{
				imos[lt] += 1;
				imos[m-1] -= 1;
				imos[0] += 1;
				imos[rt] -= 1;
			}
		}
		rep(i,0,m-1){
			imos[i+1]+=imos[i];
		}
		rep(i,0,m-1){
			if(imos[i] < k) return false;
		}
		return true;
	};
	
	ll ub = l + 1;
	ll lb = 0;
	while (ub - lb > 1) {
		ll t = (ub + lb) / 2;
		if (check(t)) {
			ub = t;
		}else{
			lb = t;
		}
	}
	cout << ub << '\n';
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t; cin >> t;
	while(t--) solve();

}

0