#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 1000000007
#define inf 1e18
#define fi first
#define se second
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define endl '\n'
#define pi 3.14159265359
#define TASKNAME "fence"
using namespace std;
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 102;
int dist[MAXN][MAXN];
const int costFence = 20;
const int costTree = 111;
struct point{
int x, y;
point(int _x = 0, int _y = 0){
x = _x;
y = _y;
}
point operator + (const point &other){
return point(x + other.x, y + other.y);
}
point operator - (const point &other){
return point(x - other.x, y - other.y);
}
bool operator < (const point &other) const{
return (x == other.x) ? (y < other.y) : (x < other.x);
}
};
int ccw(point a, point b, point c){
b = b - a;
c = c - a;
int val = b.x * c.y - c.x * b.y;
if (val < 0) return -1;
if (val > 0) return 1;
return 0;
}
vector<point> buildConvexHull(vector<point> polygon){
sort(polygon.begin(), polygon.end());
if (polygon.size() == 2) return polygon;
point p0 = polygon[0];
point p1 = polygon.back();
vector<point> upper;
vector<point> lower;
vector<point> convexhull;
upper.pb(p0);
lower.pb(p0);
FOR(i, 1, (int) polygon.size() - 1){
if (i == polygon.size() - 1 or ccw(p0, polygon[i], p1) < 0){
while(upper.size() > 1 and ccw(upper[upper.size() - 2], upper.back(), polygon[i]) >= 0) upper.pop_back();
upper.pb(polygon[i]);
}
if (i == polygon.size() - 1 or ccw(p0, polygon[i], p1) > 0){
while(lower.size() > 1 and ccw(lower[lower.size() - 2], lower.back(), polygon[i]) <= 0) lower.pop_back();
lower.pb(polygon[i]);
}
}
FOR(i, 0, (int) upper.size() - 1){
convexhull.pb(upper[i]);
}
FORD(i, (int) lower.size() - 2, 1){
convexhull.pb(lower[i]);
}
return convexhull;
}
vector<point> holes, trees, filtered, CH;
int n, m;
bool insidePolygon(vector<point> p, point pt){
if (p.size() == 1){
return false;
}
if (ccw(p[0], p[1], pt) == 0) return true;
FOR(i, 1, (int) p.size() - 1){
point p1 = p[i];
point p2 = p[(i + 1) % p.size()];
if (ccw(p1, p2, pt) == 0) return true;
if (ccw(p1, p2, pt) != ccw(p[0], p[1], pt)) return false;
}
return true;
}
main()
{
fast;
if (fopen(TASKNAME".inp","r")){
freopen(TASKNAME".inp","r",stdin);
freopen(TASKNAME".out","w",stdout);
}
cin >> n >> m;
FOR(i, 1, n){
int x, y;
cin >> x >> y;
holes.pb(point(x, y));
}
FOR(i, 1, m){
int x, y;
cin >> x >> y;
trees.pb(point(x, y));
}
CH = buildConvexHull(holes);
int cons = 0, ans = inf;
FOR(i, 0, m - 1){
if (insidePolygon(CH, trees[i])) filtered.pb(trees[i]);
else cons+= costTree;
}
memset(dist, 0x3f, sizeof(dist));
FOR(i, 0, n - 1){
FOR(j, 0, n - 1){
if (i == j) continue;
bool ch = true;
FOR(k, 0, (int) filtered.size() - 1){
if (ccw(holes[i], holes[j], filtered[k]) < 0) ch = false;
}
if (ch) {
dist[i][j] = 1;
// cout << i << ' ' << j << endl;
}
}
}
FOR(k, 0, n - 1){
FOR(i, 0, n - 1){
FOR(j, 0, n - 1){
minimize(dist[i][j], dist[i][k] + dist[k][j]);
}
}
}
ans = m * costTree;
FOR(i, 0, n - 1){
if (dist[i][i] < inf) minimize(ans, cons + dist[i][i] * costFence);
}
cout << ans << endl;
}
/**
Warning:
Đọc sai đề???
Cận lmao
Code imple thiếu case nào không.
Limit.
**/
컴파일 시 표준 에러 (stderr) 메시지
fence.cpp:109:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
109 | main()
| ^~~~
fence.cpp: In function 'int main()':
fence.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
113 | freopen(TASKNAME".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
fence.cpp:114:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | freopen(TASKNAME".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |