結果
| 問題 |
No.2897 2集合間距離
|
| コンテスト | |
| ユーザー |
eve__fuyuki
|
| 提出日時 | 2024-09-25 16:54:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,454 bytes |
| コンパイル時間 | 1,985 ms |
| コンパイル使用メモリ | 204,592 KB |
| 最終ジャッジ日時 | 2025-02-24 12:18:01 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 16 |
ソースコード
#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(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;
}
eve__fuyuki