QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#659987 | #7906. Almost Convex | fosov | TL | 1ms | 4104kb | C++14 | 2.3kb | 2024-10-20 01:07:12 | 2024-10-20 01:07:12 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define MOD ((int) (1e9) + 7)
#define pii pair<int, int>
#define N 2010
typedef pair<pii, int> pt;
pii vectorize(pii A, pii B) {
return pii(B.first - A.first, B.second - A.second);
}
ll cross(pii v0, pii v1) {
return 1ll * v0.first * v1.second - 1ll * v0.second * v1.first;
}
void polar_sort(vector<pt>& arr, pii center) {
sort(arr.begin(), arr.end(), [&](pt a, pt b) {
auto v0 = vectorize(center, a.first);
auto v1 = vectorize(center, b.first);
return atan2(v0.second, v0.first) < atan2(v1.second, v1.first);
});
}
pt stk[N];
int nxt[N], onhull[N];
int main() {
#ifdef TEST
freopen("zz.in", "r+", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
vector<pt> pts(n);
for (int i = 0; i < n; ++ i) {
int x, y; cin >> x >> y;
pts[i] = pt(pii(x, y), i);
}
sort(pts.begin(), pts.end());
polar_sort(pts, pts[0].first);
int sz = 0;
stk[++ sz] = pts[0];
stk[++ sz] = pts[1];
for (int i = 2; i < n; ++ i) {
while (sz >= 2) {
auto p0 = stk[sz - 1].first;
auto p1 = stk[sz].first;
auto p2 = pts[i].first;
if (cross(vectorize(p0, p1), vectorize(p0, p2)) < 0) {
-- sz;
} else {
break;
}
}
stk[++ sz] = pts[i];
}
for (int i = 1; i <= sz; ++ i) {
onhull[stk[i].second] = 1;
nxt[stk[i].second] = i == sz ? stk[1].second : stk[i+1].second;
}
int res = 1;
vector<pt> ss;
for (int i = 0; i < n; ++ i) {
auto [p, id] = pts[i];
if (onhull[id]) continue;
ss.clear();
for (int j = 0; j < n; ++ j) if (pts[j].second != id) ss.emplace_back(pts[j]);
polar_sort(ss, p);
int cont = 0;
for (int j = 0; j < ss.size(); ++ j) {
int k = j == ss.size()-1 ? 0 : j+1;
int cont = 1;
cont &= onhull[ss[j].second];
cont &= onhull[ss[k].second];
cont &= nxt[ss[j].second] == ss[k].second || nxt[ss[k].second] == ss[j].second;
res += cont;
}
}
cout << res << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
input:
7 1 4 4 0 2 3 3 1 3 5 0 0 2 4
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3952kb
input:
5 4 0 0 0 2 1 3 3 3 1
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3732kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3960kb
input:
6 0 0 3 0 3 2 0 2 1 1 2 1
output:
7
result:
ok 1 number(s): "7"
Test #5:
score: 0
Accepted
time: 0ms
memory: 4104kb
input:
4 0 0 0 3 3 0 3 3
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Time Limit Exceeded
input:
2000 86166 617851 383354 -277127 844986 386868 -577988 453392 -341125 -386775 -543914 -210860 -429613 606701 -343534 893727 841399 339305 446761 -327040 -218558 -907983 787284 361823 950395 287044 -351577 -843823 -198755 138512 -306560 -483261 -487474 -857400 885637 -240518 -297576 603522 -748283 33...