結果

問題 No.3759 Watch Fireworks
コンテスト
ユーザー Kude
提出日時 2026-10-09 22:42:58
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 900 ms / 2,000 ms
+ 454µs
コード長 2,550 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,530 ms
コンパイル使用メモリ 362,596 KB
実行使用メモリ 25,720 KB
最終ジャッジ日時 2026-10-09 22:43:11
合計ジャッジ時間 8,419 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 47
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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>;

struct S {
  ll xl, xr, yl, yr;
  static S sq(P p, ll d) {
    auto [x, y] = p;
    return S{x-d, x+d, y-d, y+d};
  };
  friend S merge(S a, S b) {
    return S{max(a.xl, b.xl), min(a.xr, b.xr), max(a.yl, b.yl), min(a.yr, b.yr)};
  }
  friend bool intersect(S a, S b) {
    return
      a.xl <= b.xr && a.xr >= b.xl &&
      a.yl <= b.yr && a.yr >= b.yl;
  }
  bool empty() {
    return !(xl <= xr && yl <= yr);
  };
};
} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<P> xy(n);
  for (auto& [x, y] : xy) {
    cin >> x >> y;
    x *= 2, y *= 2;
    tie(x, y) = pair(x - y, x + y);
  }
  ll ans = 8e9;
  rep(_, 2) {
    ll l = -1, r = 8e9;
    sort(all(xy));
    while (r - l > 1) {
      ll c = midpoint(l, r);
      S s1 = S::sq(xy[0], c), s2 = S::sq(xy[n-1], c);
      static vector<S> todo;
      todo.clear();
      for (auto p : xy) {
        auto s = S::sq(p, c);
        if (!intersect(s1, s)) s2 = merge(s, s2);
        else if (!intersect(s2, s)) s1 = merge(s, s1);
        else todo.emplace_back(s);
      }
      rrep(i, ssize(todo)) {
        auto s = todo[i];
        if (intersect(s1, s) && intersect(s2, s)) continue;
        if (!intersect(s1, s)) s2 = merge(s, s2);
        else if (!intersect(s2, s)) s1 = merge(s, s1);
        swap(todo.back(), todo[i]);
        todo.pop_back();
      }
      ranges::sort(todo, {}, &S::yl);
      bool ok = false;
      rep(i, ssize(todo) + 1) {
        S t1 = s1, t2 = s2;
        if (i) t1 = merge(merge(t1, todo[0]), todo[i-1]);
        if (i < ssize(todo)) t2 = merge(merge(t2, todo[i]), todo.back());
        if (!t1.empty() && !t2.empty()) {
          ok = true;
          break;
        }
      }
      (ok ? r : l) = c;
    }
    chmin(ans, r);
    for (auto& [x, y] : xy) swap(x, y);
  }
  cout << ans << '\n'; 
}
0