結果
| 問題 |
No.2354 Poor Sight in Winter
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-16 23:28:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 387 ms / 2,000 ms |
| コード長 | 5,532 bytes |
| コンパイル時間 | 4,218 ms |
| コンパイル使用メモリ | 262,652 KB |
| 最終ジャッジ日時 | 2025-02-14 21:38:04 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (ll i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (ll i = ((ll)(n)-1); i >= 0; --i)
#define rreps(i, n) for (ll i = ((ll)(n)); i > 0; --i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); ++i)
#define repc2(i, s, n) for (ll i = (s); i <= (ll)(n); ++i)
constexpr ll inf = 2000'000'000;
constexpr ll linf = 4000000000000000000ll;
constexpr ll M7 = 1000000007ll;
constexpr ll M09 = 1000000009ll;
constexpr ll M9 = 998244353ll;
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
using namespace std;
using namespace atcoder;
template <typename T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
for (auto& e : v) os << e << " ";
return os;
}
template <typename T, typename U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) noexcept {
return os << "(" << p.first << ", " << p.second << ")";
}
#ifdef ONLINE_JUDGE
#define debug(...)
#else
#define debug(...) cerr << "<" << #__VA_ARGS__ << ">: ", debug_out(__VA_ARGS__)
template <typename T>
void debug_out(T t) {
cerr << t << endl;
}
template <typename T, typename... Args>
void debug_out(T t, Args... args) {
cerr << t << ", ";
debug_out(args...);
}
#endif
template <typename T>
struct BIT {
private:
ll n, n_;
vector<T> data[2];
void add_(ll p, ll i, T x) {
for (; i < n_; i += (i & -i)) data[p][i] += x;
}
T sum_(ll p, ll i) {
T s(0);
for (; i > 0; i -= (i & -i)) s += data[p][i];
return s;
}
T sum__(ll i) { return sum_(0, i + 1) + sum_(1, i + 1) * (i + 1); }
public:
BIT(ll n) : n(n), n_(n + 1) {
data[0].resize(n_, 0);
data[1].resize(n_, 0);
}
BIT() {}
void add(ll l, ll r, T x) {
assert(0 <= l && l < r && r <= n);
add_(0, l + 1, -x * l);
add_(0, r + 1, x * r);
add_(1, l + 1, x);
add_(1, r + 1, -x);
}
void add(ll i, T x) {
assert(0 <= i && i < n);
add(i, i + 1, x);
}
T sum(ll l, ll r) {
assert(0 <= l && l < r && r <= n);
return sum__(r - 1) - sum__(l - 1);
}
T get(ll i) {
assert(0 <= i && i < n);
return sum__(i) - sum__(i - 1);
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
cin >> n >> k;
using P = pair<ll, ll>;
P _s, _g;
cin >> _s.first >> _s.second >> _g.first >> _g.second;
P s = {_s.first - _s.second, _s.first + _s.second};
P g = {_g.first - _g.second, _g.first + _g.second};
ll minX = min(s.first, g.first), minY = min(s.second, g.second);
vector<P> v(n);
rep(i, n) {
ll a, b;
cin >> a >> b;
v[i] = {a - b, a + b};
minX = min(minX, v[i].first);
minY = min(minY, v[i].second);
}
rep(i, n) {
v[i].first -= minX;
v[i].second -= minY;
}
s.first -= minX;
s.second -= minY;
g.first -= minX;
g.second -= minY;
vector<ll> vx, vy;
auto [sx, sy] = s;
auto [gx, gy] = g;
vx.push_back(s.first);
vx.push_back(g.first);
vy.push_back(s.second);
vy.push_back(g.second);
auto cmp = [&](ll p) {
struct edge {
ll to, cost;
edge(ll to, ll cost) : to(to), cost(cost) {}
};
vector<vector<edge>> G(n + 2);
const ll si = n, gi = n + 1;
rep(i, n) {
rep(j, n) {
if (i == j)
continue;
auto [x1, y1] = v[i];
auto [x2, y2] = v[j];
ll d = max((abs(x2 - x1) + p - 1) / p - 1, (abs(y2 - y1) + p - 1) / p - 1);
G[i].emplace_back(j, d);
G[j].emplace_back(i, d);
}
}
rep(i, n) {
auto [x, y] = v[i];
ll sd = max((abs(x - sx) + p - 1) / p - 1, (abs(y - sy) + p - 1) / p - 1);
G[si].emplace_back(i, sd);
G[i].emplace_back(si, sd);
ll gd = max((abs(x - gx) + p - 1) / p - 1, (abs(y - gy) + p - 1) / p - 1);
G[gi].emplace_back(i, gd);
G[i].emplace_back(gi, gd);
}
ll sgd = max((abs(sx - gx) + p - 1) / p - 1, (abs(sy - gy) + p - 1) / p - 1);
G[si].emplace_back(gi, sgd);
G[gi].emplace_back(si, sgd);
auto dijkstra = [&](ll ip) {
using P = pair<ll, ll>;
priority_queue<P, vector<P>, greater<P>> pq;
vector<ll> d(G.size(), inf);
d.at(ip) = 0;
pq.emplace(0ll, ip);
while (!pq.empty()) {
auto u = pq.top();
pq.pop();
if (u.first > d.at(u.second))
continue;
for (const auto& eg : G.at(u.second)) {
if (d.at(eg.to) > d.at(u.second) + eg.cost) {
d.at(eg.to) = d.at(u.second) + eg.cost;
pq.emplace(d.at(eg.to), eg.to);
}
}
}
return d;
};
auto d = dijkstra(si);
return d.at(gi) <= k;
};
auto bsearch = [&]() {
ll ok = 100000000, ng = 0;
while (abs(ng - ok) > 1) {
ll mid = (ng + ok) / 2;
if (cmp(mid))
ok = mid;
else
ng = mid;
}
return ok;
};
cout << bsearch() << "\n";
return 0;
}