結果
問題 | No.2354 Poor Sight in Winter |
ユーザー | coindarw |
提出日時 | 2023-06-16 23:28:20 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 430 ms / 2,000 ms |
コード長 | 5,532 bytes |
コンパイル時間 | 4,617 ms |
コンパイル使用メモリ | 273,604 KB |
実行使用メモリ | 11,588 KB |
最終ジャッジ日時 | 2024-06-24 16:45:57 |
合計ジャッジ時間 | 9,652 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 3 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 419 ms
11,392 KB |
testcase_12 | AC | 405 ms
11,392 KB |
testcase_13 | AC | 422 ms
11,588 KB |
testcase_14 | AC | 430 ms
11,584 KB |
testcase_15 | AC | 423 ms
11,588 KB |
testcase_16 | AC | 430 ms
11,464 KB |
testcase_17 | AC | 420 ms
11,588 KB |
testcase_18 | AC | 142 ms
7,312 KB |
testcase_19 | AC | 289 ms
9,936 KB |
testcase_20 | AC | 170 ms
7,972 KB |
testcase_21 | AC | 11 ms
6,940 KB |
testcase_22 | AC | 75 ms
6,944 KB |
testcase_23 | AC | 75 ms
6,940 KB |
testcase_24 | AC | 244 ms
9,216 KB |
testcase_25 | AC | 52 ms
6,940 KB |
testcase_26 | AC | 40 ms
6,944 KB |
testcase_27 | AC | 4 ms
6,940 KB |
testcase_28 | AC | 7 ms
6,940 KB |
ソースコード
#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; }