結果
| 問題 | No.3513 Greedy Yokan Party |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-04-24 22:07:50 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 312 ms / 2,000 ms |
| コード長 | 13,433 bytes |
| 記録 | |
| コンパイル時間 | 2,336 ms |
| コンパイル使用メモリ | 229,472 KB |
| 実行使用メモリ | 6,672 KB |
| 最終ジャッジ日時 | 2026-04-24 22:08:02 |
| 合計ジャッジ時間 | 8,914 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 26 |
ソースコード
#include <numeric>
#if ! defined(ONLINE_JUDGE) && __has_include("template.hpp")
#include "template.hpp"
#else
// template start
#include <algorithm>
#include <cassert>
#include <concepts>
#include <cstdint>
#include <functional>
#include <ios>
#include <iostream>
#include <istream>
#include <limits>
#include <map>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <stdexcept>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include <version>
#include <atcoder/modint.hpp>
using namespace std;
using ll = long long;
using pall = pair<ll, ll>;
template<class T>
using vec = vector<T>;
template<class T>
using veve = vec<vec<T>>;
using vell = vec<ll>;
using vest = vec<string>;
using vepl = vec<pall>;
using vebo = basic_string<bool>;
using vevell = veve<ll>;
using vevepl = veve<pall>;
template<class T>
using mset = multiset<T>;
template<class T>
using priority_queue_ascend = priority_queue<T, vec<T>, greater<T>>;
constexpr ll inf = numeric_limits<ll>::max() / 4;
constexpr string sp{" "};
constexpr string lf{"\n"};
constexpr auto npos = string::npos;
constexpr array<pall, 4> grid_move4{{{0, 1}, {-1, 0}, {0, -1}, {1, 0}}};
constexpr array<pall, 8> grid_move8{
{{0, 1}, {-1, 0}, {0, -1}, {1, 0}, {-1, 1}, {-1, -1}, {1, -1}, {1, 1}}};
template<class T>
constexpr auto minf = [](T x, T y) { return min(x, y); };
template<class T>
constexpr auto maxf = [](T x, T y) { return max(x, y); };
#define cont continue
#define ocnt cont
#define br break
#define whlie while
#define whiel while
#define foR for
#define reutnr return
#define retunr return
#define reutrn return
#define auot auto
#define uato auto
#define uaot auto
#define atuo auto
#define cosnt const
#define conts const
#define ocnst const
#define isze size
inline auto &ciN = cin;
inline auto &icn = cin;
inline auto &icN = cin;
constexpr bool ture = true;
constexpr bool tuer = true;
constexpr bool flase = false;
namespace ra = std::ranges;
namespace vi = views;
using namespace atcoder;
#define times(N) \
static_assert(is_integral_v<remove_reference_t<decltype(N)>>, "times(): N must be integral"); \
if(const auto &_N = (N); _N >= 0) \
for(typedef remove_cvref_t<decltype(_N)> _int; \
[[maybe_unused]] const _int ii : views::iota((_int)0, _N))
#define tiems times
#define itmes times
#define lmd(e) \
[&]<class T1 = monostate, \
class T2 = monostate, \
class T3 = monostate, \
class T4 = monostate, \
class T5 = monostate, \
class T6 = monostate, \
class T7 = monostate, \
class T8 = monostate, \
class T9 = monostate>([[maybe_unused]] T1 &&_1 = {}, \
[[maybe_unused]] T2 &&_2 = {}, \
[[maybe_unused]] T3 &&_3 = {}, \
[[maybe_unused]] T4 &&_4 = {}, \
[[maybe_unused]] T5 &&_5 = {}, \
[[maybe_unused]] T6 &&_6 = {}, \
[[maybe_unused]] T7 &&_7 = {}, \
[[maybe_unused]] T8 &&_8 = {}, \
[[maybe_unused]] T9 &&_9 = {}) -> decltype(auto) { return e; }
#define lmd_aply(e) \
[&]<class T>(T &&t) -> decltype(auto) { return apply(lmd(e), std::forward<T>(t)); }
struct no_output_stream {
no_output_stream &operator<<(auto &&) {
return *this;
}
no_output_stream &operator<<(std::ostream &(*)(std::ostream &)) {
return *this;
}
no_output_stream &operator<<(std::ios_base &(*)(std::ios_base &)) {
return *this;
}
};
#ifdef ONLINE_JUDGE
inline no_output_stream clog_;
#define clog clog_
#endif
template<class T>
concept out_stream = same_as<ostream, T> || same_as<no_output_stream, T>;
template<int M>
istream &operator>>(istream &in, static_modint<M> &i) {
ll tmp;
in >> tmp;
i = tmp;
return in;
}
template<int id>
istream &operator>>(istream &in, dynamic_modint<id> &i) {
ll tmp;
in >> tmp;
i = tmp;
return in;
}
template<int M>
out_stream auto &operator<<(out_stream auto &out, const static_modint<M> &i) {
return out << i.val();
}
template<int id>
out_stream auto &operator<<(out_stream auto &out, const dynamic_modint<id> &i) {
return out << i.val();
}
template<class T, class U>
istream &operator>>(istream &in, pair<T, U> &p) {
return in >> p.first >> p.second;
}
template<class T, class U>
out_stream auto &operator<<(out_stream auto &out, const pair<T, U> &p) {
return out << p.first << sp << p.second;
}
template<class T>
istream &operator>>(istream &in, vec<T> &v) {
for(auto &e : v) {
in >> e;
}
return in;
}
template<class... Ts>
istream &in(Ts &...vecs) {
static_assert(sizeof...(vecs) != 0, "myfunc::in(): At least one vector must be provided");
const array<size_t, sizeof...(vecs)> sizes = {vecs.size()...};
if(ra::find_if(sizes, lmd(_1 != sizes[0])) != sizes.end()) {
throw invalid_argument("myfunc::in(): All vectors must have the same size");
}
times(*sizes.begin()) {
((cin >> vecs[ii]), ...);
}
return cin;
}
auto out(std::ranges::input_range auto &&v, const string &delim, out_stream auto &out)
-> add_lvalue_reference_t<decltype(out)> {
for(auto &&e : v) {
out << e << delim;
}
return out;
}
decltype(auto) out(std::ranges::input_range auto &&v, const string &delim) {
return out(v, delim, cout);
}
inline void yes() {
cout << "Yes" << lf;
}
inline void no() {
cout << "No" << lf;
}
inline void yesu() {
cout << "YES" << lf;
}
inline void nou() {
cout << "NO" << lf;
}
// [mi, ma)
[[nodiscard]] inline uint64_t randint(const uint64_t mi, const uint64_t ma) {
static mt19937_64 mt(random_device{}());
assert(mi != ma);
if(mi > ma) [[unlikely]]
return randint(ma, mi);
const uint64_t w = ma - mi;
uint64_t r;
do {
r = mt();
} while(mt.max() - mt.max() % w <= r);
return r % w + mi;
}
template<class T, class U>
requires common_with<T, U> && (not is_reference_v<common_type_t<T, U>>)
[[nodiscard]] constexpr auto min(T &&a, U &&b) {
using CT = common_type_t<T, U>;
static_assert(
requires (CT ca, CT cb) {
{ ca < cb } -> convertible_to<bool>;
}, "common type must be comparable");
if constexpr(requires () {
{ b < a } -> convertible_to<bool>;
}) {
if(b < a)
return CT(std::forward<U>(b));
else
return CT(std::forward<T>(a));
} else {
const CT ca(std::forward<T>(a));
const CT cb(std::forward<U>(b));
return (cb < ca) ? cb : ca;
}
}
template<class T>
[[nodiscard]] constexpr const T &min(T &a, T &b) {
return std::min(a, b);
}
template<class T, class U>
requires common_with<T, U> && (not is_reference_v<common_type_t<T, U>>)
[[nodiscard]] constexpr auto max(T &&a, U &&b) {
using CT = common_type_t<T, U>;
static_assert(
requires (CT ca, CT cb) {
{ ca < cb } -> convertible_to<bool>;
}, "common type must be comparable");
if constexpr(requires () {
{ a < b } -> convertible_to<bool>;
}) {
if(a < b)
return CT(std::forward<U>(b));
else
return CT(std::forward<T>(a));
} else {
const CT ca(std::forward<T>(a));
const CT cb(std::forward<U>(b));
return (ca < cb) ? cb : ca;
}
}
template<class T>
[[nodiscard]] constexpr const T &max(T &a, T &b) {
return std::max(a, b);
}
template<class... Args>
[[nodiscard]] auto reduce(std::ranges::input_range auto &&r, Args &&...args) {
auto &&cr = views::common(std::forward<decltype(r)>(r));
return std::reduce(std::ranges::begin(cr), std::ranges::end(cr), std::forward<Args>(args)...);
}
template<signed_integral T>
auto popcount(T x) {
return popcount(static_cast<make_unsigned_t<T>>(x));
}
template<signed_integral T>
auto bit_width(T x) {
return bit_width(static_cast<make_unsigned_t<T>>(x));
}
template<signed_integral T>
auto bit_floor(T x) {
return bit_floor(static_cast<make_unsigned_t<T>>(x));
}
template<signed_integral T>
auto bit_ceil(T x) {
return bit_ceil(static_cast<make_unsigned_t<T>>(x));
}
[[nodiscard]] constexpr ll powll(ll a, ll b, const ll m = numeric_limits<ll>::max()) {
if(b < 0) [[unlikely]]
throw invalid_argument("powll(): exponent less than zero");
if(m < 1) [[unlikely]]
throw invalid_argument("powll(): modulo less than one");
a %= m;
ll ret = 1;
while(b) {
if(b % 2) ret *= a, ret %= m;
a *= a, a %= m;
b /= 2;
}
return ret;
}
template<class T, class U>
requires assignable_from<T &, U> && totally_ordered_with<T, U>
bool mini(T &var, U &&val) {
const bool cmp = var > val;
if(cmp) var = std::forward<U>(val);
return cmp;
}
template<class T, class U>
requires assignable_from<T &, U> && totally_ordered_with<T, U>
bool maxi(T &var, U &&val) {
const bool cmp = var < val;
if(cmp) var = std::forward<U>(val);
return cmp;
}
template<template<typename...> class Map, class K, class V>
requires same_as<Map<K, V>, map<K, V>> || same_as<Map<K, V>, unordered_map<K, V>>
[[nodiscard]] const V &vmin(const Map<K, V> &m) {
assert(not m.empty());
return *std::ranges::min_element(m | views::values);
}
template<template<typename...> class Map, class K, class V>
requires same_as<Map<K, V>, map<K, V>> || same_as<Map<K, V>, unordered_map<K, V>>
[[nodiscard]] const V &vmax(const Map<K, V> &m) {
assert(not m.empty());
return *std::ranges::max_element(m | views::values);
}
class [[nodiscard]] grid {
public:
grid(const ll h, const ll w) noexcept : height(h), width(w) {}
[[nodiscard]] ll operator()(const ll i, const ll j) const noexcept {
if(not isvalid(i, j)) return -1;
return i * width + j;
}
[[nodiscard]] ll operator()(const pall &p) const noexcept {
return (*this)(p.first, p.second);
}
protected:
bool isvalid(const ll i, const ll j) const noexcept {
return 0 <= i && 0 <= j && i < height && j < width;
}
const ll height, width;
};
class [[nodiscard]] grid_seen : public grid {
public:
grid_seen(const ll h, const ll w) : grid(h, w) {
visited = vebo(h * w, false);
}
[[nodiscard]] bool &seen(const ll i, const ll j) & {
if(not isvalid(i, j)) [[unlikely]]
throw out_of_range("grid_seen::seen(): out of range");
return visited[i * width + j];
}
[[nodiscard]] bool &seen(const pall &p) & {
return seen(p.first, p.second);
}
template<class... Args>
[[nodiscard]] bool &sen(Args &&...args) & {
return seen(forward<Args>(args)...);
}
private:
vebo visited;
};
template<auto defval, class... Args>
requires convertible_to<decltype(defval), typename map<Args...>::mapped_type>
class default_map : public map<Args...> {
using Map = map<Args...>;
template<class U>
static constexpr bool comparable = requires (Map::key_compare c, Map::key_type t, U u) {
c(t, u);
c(u, t);
};
public:
#ifdef __cpp_lib_associative_heterogeneous_insertion
template<convertible_to<typename Map::key_type> U>
requires comparable<U>
Map::mapped_type &operator[](const U &key) {
Map::try_emplace(key, defval);
return Map::operator[](key);
}
template<convertible_to<typename Map::key_type> U>
requires comparable<U>
Map::mapped_type &operator[](const U &&key) {
Map::try_emplace(key, defval);
return Map::operator[](key);
}
#else
Map::mapped_type &operator[](const Map::key_type &key) {
Map::try_emplace(key, defval);
return Map::operator[](key);
}
Map::mapped_type &operator[](const Map::key_type &&key) {
Map::try_emplace(key, defval);
return Map::operator[](key);
}
#endif
};
template<auto defval, class... Args>
requires is_convertible_v<decltype(defval), typename unordered_map<Args...>::mapped_type>
class default_unordered_map : public unordered_map<Args...> {
using Map = unordered_map<Args...>;
template<class U>
static constexpr bool hashable = requires (Map::hasher h, U u) { h(u); };
public:
#ifdef __cpp_lib_associative_heterogeneous_insertion
template<class U>
requires hashable<U>
Map::mapped_type &operator[](const U &key) {
Map::try_emplace(key, defval);
return Map::operator[](key);
}
template<class U>
requires hashable<U>
Map::mapped_type &operator[](const U &&key) {
Map::try_emplace(key, defval);
return Map::operator[](key);
}
#else
Map::mapped_type &operator[](const Map::key_type &key) {
Map::try_emplace(key, defval);
return Map::operator[](key);
}
Map::mapped_type &operator[](const Map::key_type &&key) {
Map::try_emplace(key, defval);
return Map::operator[](key);
}
#endif
};
template<class T, class U>
requires requires (mset<T>::key_compare c, T t, U u) {
{ c(t, u) } -> convertible_to<bool>;
}
auto erase_single(mset<T> &mset, U &&v) {
const auto it = mset.find(v);
if(it == mset.end()) return mset.end();
return mset.erase(it);
}
inline ll isqrt(const ll x) {
assert(x >= 0);
ll rx = (ll)sqrt(x);
while((rx + 1) * (rx + 1) <= x) rx++;
while(rx * rx > x) rx--;
return rx;
}
inline ll divceil(const ll a, const ll b) {
assert(b != 0);
return (a + b - 1) / b;
}
// template end
#endif
#define MOD_IS_998 1
#ifdef MOD_IS_998
using mint = modint998244353;
#else
using mint = modint1000000007;
#endif
constexpr ll MOD = mint::mod();
static void init();
static void solve();
int main(void) {
cin.tie(nullptr);
ios::sync_with_stdio(false);
init();
ll t = 1;
// cin >> t;
times(t) solve();
return 0;
}
void init() {}
void solve() {
ll n, k, l;
cin >> n >> l >> k;
vell a(n);
cin >> a;
a.insert(a.begin(), 0);
n++;
ll ok = 0, ng = l + 1;
while(abs(ok - ng) > 1) {
const ll mid = midpoint(ok, ng);
ll smi = inf;
ll wmi = inf;
ll r = n;
vell w(n, inf);
for(intmax_t i = n - 1; i >= 0; i--) {
if(a[i] + mid > l) cont;
const ll j = ra::lower_bound(a, a[i] + mid) - a.begin();
while(j < r) r--, mini(wmi, w[r]);
w[i] = j - i;
mini(smi, w[i] + wmi);
}
if(n - (smi - 2) >= k + 1) {
ok = mid;
} else {
ng = mid;
}
}
cout << ok;
}