結果
問題 | No.2354 Poor Sight in Winter |
ユーザー | coindarw |
提出日時 | 2023-06-16 23:19:57 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,854 bytes |
コンパイル時間 | 10,071 ms |
コンパイル使用メモリ | 276,676 KB |
実行使用メモリ | 11,588 KB |
最終ジャッジ日時 | 2024-06-24 16:31:24 |
合計ジャッジ時間 | 9,564 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | WA | - |
testcase_12 | AC | 316 ms
11,520 KB |
testcase_13 | AC | 336 ms
11,588 KB |
testcase_14 | AC | 323 ms
11,584 KB |
testcase_15 | AC | 320 ms
11,460 KB |
testcase_16 | AC | 332 ms
11,440 KB |
testcase_17 | AC | 322 ms
11,564 KB |
testcase_18 | AC | 126 ms
7,440 KB |
testcase_19 | AC | 231 ms
9,940 KB |
testcase_20 | AC | 148 ms
7,844 KB |
testcase_21 | WA | - |
testcase_22 | AC | 67 ms
5,376 KB |
testcase_23 | AC | 67 ms
5,376 KB |
testcase_24 | AC | 195 ms
9,160 KB |
testcase_25 | AC | 44 ms
5,376 KB |
testcase_26 | AC | 34 ms
5,376 KB |
testcase_27 | AC | 4 ms
5,376 KB |
testcase_28 | AC | 6 ms
5,376 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; ll maxX = max(s.first, g.first), maxY = max(s.second, g.second); rep(i, n) { maxX = max(maxX, v[i].first); maxY = max(maxY, v[i].second); } 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); rep(i, n) { auto [x, y] = v[i]; if (s.first <= x && x <= g.first) vx.push_back(x); if (s.second <= y && y <= g.second) vy.push_back(y); } sort(all(vx)); sort(all(vy)); vx.erase(unique(all(vx)), vx.end()); vy.erase(unique(all(vy)), vy.end()); 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); } 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 = 10000000, 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; }