結果

問題 No.2612 Close the Distance
ユーザー 👑 hos.lyrichos.lyric
提出日時 2024-01-19 21:52:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 779 ms / 3,000 ms
コード長 2,559 bytes
コンパイル時間 1,060 ms
コンパイル使用メモリ 115,212 KB
実行使用メモリ 9,532 KB
最終ジャッジ日時 2024-01-20 00:17:16
合計ジャッジ時間 13,535 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 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 369 ms
8,316 KB
testcase_07 AC 392 ms
8,316 KB
testcase_08 AC 331 ms
8,316 KB
testcase_09 AC 317 ms
8,316 KB
testcase_10 AC 369 ms
8,316 KB
testcase_11 AC 321 ms
8,316 KB
testcase_12 AC 337 ms
8,316 KB
testcase_13 AC 291 ms
8,316 KB
testcase_14 AC 292 ms
8,316 KB
testcase_15 AC 304 ms
8,316 KB
testcase_16 AC 643 ms
9,528 KB
testcase_17 AC 588 ms
9,528 KB
testcase_18 AC 625 ms
9,532 KB
testcase_19 AC 647 ms
9,528 KB
testcase_20 AC 779 ms
9,532 KB
testcase_21 AC 646 ms
9,532 KB
testcase_22 AC 769 ms
9,532 KB
testcase_23 AC 757 ms
9,528 KB
testcase_24 AC 728 ms
9,528 KB
testcase_25 AC 643 ms
9,532 KB
testcase_26 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


constexpr Int INF = 1001001001001001001LL;

int N;
vector<Int> X, Y;

bool solve(Int thr, int k, const vector<int> &us) {
  if (!us.size()) return true;
  if (!k) return false;
  Int xs[2] = {-INF, +INF};
  Int ys[2] = {-INF, +INF};
  for (const int u : us) {
    chmax(xs[0], X[u]); chmin(xs[1], X[u] + thr);
    chmax(ys[0], Y[u]); chmin(ys[1], Y[u] + thr);
  }
  if (k == 1) {
    return (xs[0] <= xs[1] && ys[0] <= ys[1]);
  }
  for (int s = 0; s < 2; ++s) for (int t = 0; t < 2; ++t) {
    vector<int> vs;
    for (const int u : us) {
      if (true
          && X[u] <= xs[s] && xs[s] <= X[u] + thr
          && Y[u] <= ys[t] && ys[t] <= Y[u] + thr
      ) {
        //
      } else {
        vs.push_back(u);
      }
    }
    if (solve(thr, k - 1, vs)) {
      return true;
    }
  }
  return false;
}

bool check(Int thr) {
  vector<int> us(N);
  for (int u = 0; u < N; ++u) us[u] = u;
  return solve(thr, 3, us);
}

int main() {
  for (; ~scanf("%d", &N); ) {
    X.resize(N);
    Y.resize(N);
    for (int u = 0; u < N; ++u) {
      int a, b;
      scanf("%d%d", &a, &b);
      X[u] = a + b;
      Y[u] = a - b;
    }
    
    Int lo = -1, hi = 2001001001LL;
    for (; lo + 1 < hi; ) {
      const Int mid = (lo + hi) / 2;
      (check(mid) ? hi : lo) = mid;
    }
    printf("%lld\n", hi);
break;
  }
  return 0;
}
0