結果

問題 No.2612 Close the Distance
ユーザー KudeKude
提出日時 2024-01-19 23:11:45
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 499 ms / 3,000 ms
コード長 2,533 bytes
コンパイル時間 3,328 ms
コンパイル使用メモリ 274,492 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-20 00:19:21
合計ジャッジ時間 11,386 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 230 ms
6,676 KB
testcase_07 AC 217 ms
6,676 KB
testcase_08 AC 224 ms
6,676 KB
testcase_09 AC 230 ms
6,676 KB
testcase_10 AC 227 ms
6,676 KB
testcase_11 AC 233 ms
6,676 KB
testcase_12 AC 235 ms
6,676 KB
testcase_13 AC 240 ms
6,676 KB
testcase_14 AC 233 ms
6,676 KB
testcase_15 AC 250 ms
6,676 KB
testcase_16 AC 403 ms
6,676 KB
testcase_17 AC 429 ms
6,676 KB
testcase_18 AC 455 ms
6,676 KB
testcase_19 AC 499 ms
6,676 KB
testcase_20 AC 382 ms
6,676 KB
testcase_21 AC 461 ms
6,676 KB
testcase_22 AC 381 ms
6,676 KB
testcase_23 AC 412 ms
6,676 KB
testcase_24 AC 436 ms
6,676 KB
testcase_25 AC 398 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<ll,ll>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<P> p(n);
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    p[i] = {x + y, x - y};
  }
  ll l = -1, r = 2000000000;
  constexpr long long INF = 1002003004005006007;
  while (r - l > 1) {
    ll c = (l + r) / 2;
    auto covered = [&](P a, P b) {
      ll dx = b.first - a.first, dy = b.second - a.second;
      return 0 <= dx && dx <= c && 0 <= dy && dy <= c;
    };
    bool ok = [&]() {
      rep(_, 4) {
        ll xmn = INF, ymn = INF, xmx = -INF, ymx = -INF;
        for (auto [x, y] : p) {
          chmin(xmn, x);
          chmin(ymn, y);
          chmax(xmx, x);
          chmax(ymx, y);
        }
        P p1{xmn, ymn}, p4{xmx - c, ymx - c};
        xmn = INF, ymn = INF, xmx = -INF, ymx = -INF;
        for (auto pi : p) {
          if (!covered(p1, pi) && !covered(p4, pi)) {
            auto [x, y] = pi;
            chmin(xmn, x);
            chmin(ymn, y);
            chmax(xmx, x);
            chmax(ymx, y);
          }
        }
        if (xmx - xmn <= c && ymx - ymn <= c) return true;
        xmn = INF, ymn = INF, xmx = -INF, ymx = -INF;
        for (auto pi : p) {
          if (!covered(p1, pi)) {
            auto [x, y] = pi;
            chmin(xmn, x);
            chmin(ymn, y);
            chmax(xmx, x);
            chmax(ymx, y);
          }
        }
        P p2{xmn, ymx - c}, p3{xmx - c, ymn};
        bool ok = true;
        for (auto pi : p) {
          if (!covered(p1, pi) && !covered(p2, pi) && !covered(p3, pi)) {
            ok = false;
            break;
          }
        }
        if (ok) return true;
        for (auto& [x, y] : p) {
          tie(x, y) = pair(-y, x);
        }
      }
      return false;
    }();
    (ok ? r : l) = c;
  }
  cout << r << '\n';
}
0