結果
問題 |
No.2897 2集合間距離
|
ユーザー |
![]() |
提出日時 | 2024-09-25 16:55:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,116 ms / 3,500 ms |
コード長 | 1,484 bytes |
コンパイル時間 | 1,985 ms |
コンパイル使用メモリ | 204,908 KB |
最終ジャッジ日時 | 2025-02-24 12:18:28 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector<pair<int, int>> s(n); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; s[i] = {x + y, x - y}; } int m; cin >> m; vector<pair<int, int>> t(m); for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; t[i] = {x + y, x - y}; } sort(s.begin(), s.end()); sort(t.begin(), t.end()); int ng = -1, ok = 1e6; while (ng + 1 < ok) { int mid = (ng + ok) / 2; multiset<int> st; bool is_ok = false; int l = 0, r = 0; for (auto [u, v] : s) { while (r < m && t[r].first <= u + mid) { st.insert(t[r].second); r++; } while (l < r && t[l].first < u - mid) { st.erase(st.find(t[l].second)); l++; } // cout << l << " " << r << endl; auto it = st.lower_bound(v); if (it != st.end() && *it <= v + mid) { is_ok = true; break; } if (it != st.begin() && *prev(it) >= v - mid) { is_ok = true; break; } } if (is_ok) { ok = mid; } else { ng = mid; } } cout << ok << endl; }