結果
| 問題 | 
                            No.2897 2集合間距離
                             | 
                    
| コンテスト | |
| ユーザー | 
                             vjudge1
                         | 
                    
| 提出日時 | 2024-09-25 15:33:24 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 110 ms / 3,500 ms | 
| コード長 | 1,004 bytes | 
| コンパイル時間 | 779 ms | 
| コンパイル使用メモリ | 84,584 KB | 
| 実行使用メモリ | 20,736 KB | 
| 最終ジャッジ日時 | 2024-09-25 15:33:29 | 
| 合計ジャッジ時間 | 2,857 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 24 | 
ソースコード
#include <iostream>
#include <vector>
using namespace std;
const int MAXN = 2e5 + 5, MAXV = 2e3 + 3;
int n, m, a[MAXN], b[MAXN], c[MAXV][MAXV];
bool Check(int dis) {
  for (int i = 1; i <= n; i++) {
    int lx = max(1, a[i] - dis), rx = min(2000, a[i] + dis);
    int ly = max(1, b[i] - dis), ry = min(2000, b[i] + dis);
    if (c[rx][ry] - c[lx - 1][ry] - c[rx][ly - 1] + c[lx - 1][ly - 1] > 0) {
      return 1;
    }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1, x, y; i <= n; i++) {
    cin >> x >> y;
    a[i] = x + y + 1, b[i] = x - y + 1001;
  }
  cin >> m;
  for (int i = 1, x, y; i <= m; i++) {
    cin >> x >> y;
    c[x + y + 1][x - y + 1001]++;
  }
  for (int i = 1; i < MAXV; i++) {
    for (int j = 1; j < MAXV; j++) {
      c[i][j] += c[i][j - 1] + c[i - 1][j] - c[i - 1][j - 1];
    }
  }
  int l = 0, r = MAXV;
  while (l < r) {
    int mid = (l + r) >> 1;
    Check(mid) ? r = mid : l = mid + 1;
  }
  cout << l;
  return 0;
}
            
            
            
        
            
vjudge1