結果
| 問題 |
No.2897 2集合間距離
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-20 22:24:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 352 ms / 3,500 ms |
| コード長 | 2,781 bytes |
| コンパイル時間 | 1,246 ms |
| コンパイル使用メモリ | 118,208 KB |
| 実行使用メモリ | 9,672 KB |
| 最終ジャッジ日時 | 2024-09-20 22:24:41 |
| 合計ジャッジ時間 | 5,164 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 |
ソースコード
#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 = 1001001001;
void bChmax(vector<int> &bit, int pos, int val) {
const int bitN = bit.size();
for (int x = pos; x < bitN; x |= x + 1) chmax(bit[x], val);
}
int bMax(const vector<int> &bit, int pos) {
int ret = -INF;
for (int x = pos; x > 0; x &= x - 1) chmax(ret, bit[x - 1]);
return ret;
}
constexpr int LIM = 1000;
int N[2];
vector<int> X[2], Y[2];
int main() {
for (; ; ) {
for (int h = 0; h < 2; ++h) {
if (!~scanf("%d", &N[h])) return 0;
X[h].resize(N[h]);
Y[h].resize(N[h]);
for (int u = 0; u < N[h]; ++u) {
scanf("%d%d", &X[h][u], &Y[h][u]);
}
}
int ans = INF;
for (int dir = 0; dir < 4; ++dir) {
vector<pair<int, int>> es(N[0] + N[1]);
for (int u = 0; u < N[0]; ++u) es[u] = make_pair(X[0][u], u);
for (int v = 0; v < N[1]; ++v) es[N[0] + v] = make_pair(X[1][v], N[0] + v);
sort(es.begin(), es.end());
vector<int> bit(LIM + 1, -INF);
for (const auto &e : es) {
if (e.second < N[0]) {
const int u = e.second;
bChmax(bit, Y[0][u], X[0][u] + Y[0][u]);
} else {
const int v = e.second - N[0];
const int res = bMax(bit, Y[1][v] + 1);
chmin(ans, (X[1][v] + Y[1][v]) - res);
}
}
for (int h = 0; h < 2; ++h) {
for (int u = 0; u < N[h]; ++u) {
const int x = X[h][u];
const int y = Y[h][u];
X[h][u] = LIM - y;
Y[h][u] = x;
}
}
}
printf("%d\n", ans);
}
return 0;
}