#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define x first
#define y second
using namespace std;
bool cw(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
return a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y) < 0;
}
bool ccw(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
return a.x*(b.y-c.y)+b.x*(c.y-a.y)+c.x*(a.y-b.y) > 0;
}
void hull(vector<pair<int, int>>& a) {
if (a.size() == 1)
return;
sort(a.begin(), a.end());
pair<int, int> p1 = a[0], p2 = a.back();
vector<pair<int, int>> up, down;
up.push_back(p1);
down.push_back(p1);
for (int i = 1; i < (int)a.size(); i++) {
if (i == a.size() - 1 || cw(p1, a[i], p2)) {
while (up.size() >= 2 && !cw(up[up.size()-2], up[up.size()-1], a[i]))
up.pop_back();
up.push_back(a[i]);
}
if (i == a.size() - 1 || ccw(p1, a[i], p2)) {
while(down.size() >= 2 && !ccw(down[down.size()-2], down[down.size()-1], a[i]))
down.pop_back();
down.push_back(a[i]);
}
}
a = up;
for (int i = down.size() - 2; i > 0; i--)
a.push_back(down[i]);
}
vector<pair<int, int>> v;
bool inside(pair<int, int> p) {
for (int i = 0; i < (int)v.size(); ++i) {
if (ccw(v[i], v[(i + 1) % v.size()], p)) {
return false;
}
}
return true;
}
int const N = 110;
bitset<N> bio;
int mat[N][N];
int shortest_cycle() {
int sol = 1e9;
int n = v.size();
for(int k = 0; k < n; ++k)
for(int i = 0; i < n; ++i)
for(int j = 0; j < n; ++j)
if(mat[i][j] > mat[i][k] + mat[k][j])
mat[i][j] = mat[i][k] + mat[k][j];
for(int i = 0; i < n; ++i)
sol = min(sol, mat[i][i]);
return sol;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
v.resize(n);
for (auto &[a, b] : v) cin >> a >> b;
hull(v);
vector<pair<int, int>> t;
for (int i = 0; i < m; ++i) {
pair<int, int> p;
cin >> p.x >> p.y;
if (inside(p)) {
t.push_back(p);
}
}
if (t.size() == 0) {
cout << 111ll * m << '\n';
return 0;
}
memset(mat, 0x3f, sizeof mat);
for (int i = 0; i < v.size(); ++i) {
for (int k = 0; k < v.size(); ++k) {
if (i == k) continue;
bool b = true;
for (int j = 0; j < (int)t.size(); ++j) {
if (ccw(v[i], v[k], t[j])) {
b = false;
break;
}
}
if (b) {
mat[i][k] = 1;
}
}
}
cout << 20ll * shortest_cycle() + 111ll * (m - t.size());
return 0;
}
Compilation message
fence.cpp: In function 'void hull(std::vector<std::pair<int, int> >&)':
fence.cpp:27:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | if (i == a.size() - 1 || cw(p1, a[i], p2)) {
| ~~^~~~~~~~~~~~~~~
fence.cpp:32:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if (i == a.size() - 1 || ccw(p1, a[i], p2)) {
| ~~^~~~~~~~~~~~~~~
fence.cpp: In function 'int main()':
fence.cpp:96:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for (int i = 0; i < v.size(); ++i) {
| ~~^~~~~~~~~~
fence.cpp:97:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
97 | for (int k = 0; k < v.size(); ++k) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
492 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |