# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1280350 | daotuankhoi | SIR (COI15_sir) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
template <class T> bool ckmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template <class T> bool ckmin(T &a, T b) { return a > b ? (a = b, true) : false; }
struct Vec {
ll x, y;
Vec(ll _x = 0, ll _y = 0) : x(_x), y(_y) {}
Vec operator-(Vec o) {
return Vec(x - o.x, y - o.y);
}
bool operator<(Vec o) {
return (x < o.x || (x == o.x && y < o.y));
}
};
using Point = Vec;
ll cross(Vec a, Vec b) {
return (a.x * b.y) - (a.y * b.x);
}
bool ccw(Point a, Point b, Point c) {
Vec ab = b - a;
Vec ac = c - a;
return cross(ab, ac) > 0;
}
bool cw(Point a, Point b, Point c) {
Vec ab = b - a;
Vec ac = c - a;
return cross(ab, ac) < 0;
}
bool chk(Point a, Point b, Point c) {
Vec ab = b - a;
Vec ac = c - a;
return cross(ab, ac) < 0;
}
ll area(Point a, Point b, Point c) {
array<Point, 4> e;
e[0] = a; e[1] = b, e[2] = c, e[3] = a;
ll ans = 0;
for (int i = 0; i < 3; i++) {
ans += (e[i].x * e[i+1].y) - (e[i+1].x * e[i].y);
}
return absll(ans);
}
const int MAXN = 3e5 + 5;
Point a[MAXN], d[MAXN];
int main() {
#define NAME "test"
if (fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
for (int i = 0; i < n; i++) cin >> d[i].x >> d[i].y;
int m; cin >> m;
for (int i = 1; i <= m; i++) cin >> a[i].x >> a[i].y;
// reverse(d + 1, d + n + 1);
sort(a + 1, a + m + 1);
vector<Point> hull;
if (m < 3) {
for (int i = 1; i <= m; i++) hull.emplace_back(a[i]);
} else {
for (int i = 1; i <= m; i++) {
while ((int)hull.size() >= 2 && chk(hull[(int)hull.size() - 2], hull[(int)hull.size() - 1], a[i])) hull.pop_back();
hull.emplace_back(a[i]);
}
int sz = hull.size();
for (int i = m - 1; i >= 1; i--) {
while ((int)hull.size() >= sz + 1 && chk(hull[(int)hull.size() - 2], hull[(int)hull.size() - 1], a[i])) hull.pop_back();
hull.emplace_back(a[i]);
}
/// CCW
hull.pop_back();
}
int cur = 0, tt = 0;
m = hull.size();
if (m != 1) {
for (int i = 0; i < m; i++) {
if (ccw(d[0], hull[i], hull[(i + 1) % m])) {
cur = i;
break;
}
}
}
ll s = 0;
// cerr << calc(d[0], hull[0], hull[1]) << '\n';
// cerr << d[0].x << ' ' << d[0].y << '\n';
// cerr << hull[0].x << ' ' << hull[0].y << '\n';
// cerr << hull[1].x << ' ' << hull[1].y << '\n';
// for (auto [x, y] : hull) {
// cout << x << ' ' << y << '\n';
// }
for (int i = 2; i < n; i++) {
if (cw(d[0], hull[cur], d[i])) {
s += area(d[0], d[i - 1], d[i]);
tt = i;
} else break;
}
// cerr << s << ' ' << tt << ' ' << cur << '\n';
// cerr << hull[1].x << ' ' << hull[1].y << '\n';
//cerr << ccw(Point(-3, -4), Point(0, -3), Point(2, 0)) << '\n';
//cerr << ccw(d[1], hull[cur], hull[(cur + 1) % m]) << '\n';
//debug(area(Point(0, 1), Point(2, 3), Point(0, 3)));
assert(s != )
ll ans = s;
tt = max(tt + 1, 1);
for (int i = 1; i < n; i++) {
if (m != 1) {
while (!ccw(d[i], hull[cur], hull[(cur + 1) % m])) {
cur++;
if (cur >= m) cur -= m;
}
}
// cerr << i << ' ' << cur << '\n';
s -= area(d[(i - 1 + n) % n], d[(tt - 1 + n) % n], d[i]);
// cerr << i << '\n';
// debug(s, area(d[i - 1], d[(tt - 1 + n) % n], d[i]));
// debug(d[i].x, d[i].y, d[i - 1].x, d[i - 1].y, d[tt - 1].x, d[tt - 1].y);
if (tt == i) tt = (tt + 1) % n;
// if (tt == 1) tt = (tt + 1) % n;
while (cw(d[i], hull[cur], d[tt])) {
s += area(d[tt], d[(tt - 1 + n) % n], d[i]);
// debug(tt, s, area(d[tt], d[(tt - 1 + n) % n], d[i]));
tt++;
tt %= n;
if (tt == i) break;
}
// debug(i, tt, s);
ckmax(ans, s);
}
cout << ans << '\n';
return 0;
}