QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#278993 | #7906. Almost Convex | ucup-team1508# | WA | 19ms | 3896kb | C++20 | 4.6kb | 2023-12-08 00:39:50 | 2023-12-08 00:39:50 |
Judging History
answer
#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define Fd(i, a, b) for(int i = a; i >= b; i --)
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
typedef double db;
const db eps = 1e-8;
int sgn(db x) {
if(fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
}
struct point {
db x, y;
int id;
point() {}
point(db x, db y, int id) : x(x), y(y), id(id) {}
point operator + (point B) {return point(x + B.x, y + B.y, id);}
point operator - (point B) {return point(x - B.x, y - B.y, id);}
// point operator = (point B) {return point(B.x, B.y, B.id);}
bool operator == (point B) {return sgn(x - B.x) == 0 && sgn(y - B.y) == 0;}
bool operator < (point B) {return sgn(x - B.x) < 0 || (sgn(x - B.x) == 0 && sgn(y - B.y) < 0);}
};
bool cmp(point a, point b) {
return sgn(a.y - b.y) == 0 ? sgn(a.x - b.x) < 0 : sgn(a.y - b.y) <= 0;
}
db cross(point A, point B) {return A.x * B.y - A.y * B.x;}
bool get_region(point a) {
return a.y <= 0 && (a.x < 0 || a.y < 0);
}
point o = {0, 0, 0};
bool cmp1(point a, point b) {
point p = a - o, q = b - o;
int r1 = get_region(a), r2 = get_region(b);
if(r1 != r2) return r1 < r2;
if(cross(p, q) == 0) return a.x < b.x;
return cross(p, q) > 0;
}
bool cmp2(point a, point b) {
point p = a - o, q = b - o;
int r1 = get_region(a), r2 = get_region(b);
if(r1 != r2) return r1 > r2;
if(cross(p, q) == 0) return a.x < b.x;
return cross(p, q) < 0;
}
const int N = 2005;
int convex_hull(vector<point> p, int n, int *ch) {
int v = 0;
F(i, 0, n - 1) {
while(v >= 2 && sgn(cross(p[ch[v - 1]] - p[ch[v - 2]], p[i] - p[ch[v - 1]])) <= 0) v --;
ch[v ++] = i;
} int j = v;
Fd(i, n - 2, 0) {
while(v > j && sgn(cross(p[ch[v - 1]] - p[ch[v - 2]], p[i] - p[ch[v - 1]])) <= 0) v --;
ch[v ++] = i;
}
return n > 1 ? v - 1 : v;
}
int ch[N], vst[N];
void sol() {
int n; cin >> n;
vector<point> a(n);
F(i, 0, n - 1) {
int x, y; cin >> x >> y;
a[i].x = x, a[i].y = y;
}
sort(a.begin(), a.end(), cmp);
int m = convex_hull(a, n, ch);
F(i, 0, n - 1) a[i].id = i;
// cout << m << endl;
// F(i, 0, m - 1) cout << ch[i] << " \n" [i == m - 1];
F(i, 0, m - 1) vst[ch[i]] = 1;
int res = 0;
F(i, 0, m - 1) {
int l = ch[i], r = ch[(i + 1) % m];
// cout << l << " " << r << "\n";
auto b = a, c = a;
vector<point> tmp(n);
o = a[l];
sort(b.begin(), b.end(), cmp1);
o = a[r];
sort(c.begin(), c.end(), cmp2);
int b0, b1;
F(j, 0, n - 1) {
if(b[j].id == a[r].id) {
b0 = (j + 1) % n;
break;
}
}
F(j, 0, n - 1) {
if(c[j].id == a[l].id) {
b1 = (j + 1) % n;
break;
}
}
// cout << b0 << " " << b1 << endl;
// cout << 1 << endl;
// cout << "szb: " << b.size() << "\n";
vector<int> pos1(n), pos2(n), ok(n);
int cnt = 0;
int tot = 0;
for(int j = b0; tot < n; j = (j + 1) % n) {
tot ++;
tmp[cnt].x = b[j].x, tmp[cnt].y = b[j].y, tmp[cnt ++].id = b[j].id;
}
// F(j, 0, n - 1) cout << b[j].id << " \n" [j == n - 1];
// cout << n << endl;
F(j, 0, n - 1) pos1[b[j].id] = j;
// cout << 1 << endl;
cnt = 0, tot = 0;
for(int j = b1; tot < n; j = (j + 1) % n) {
tot ++;
tmp[cnt].x = c[j].x, tmp[cnt].y = c[j].y, tmp[cnt ++].id = c[j].id;
}
c = tmp;
F(j, 0, n - 1) pos2[c[j].id] = j;
// cout << 1 << endl;
// F(j, 0, n - 1) cout << b[j].id << " \n" [j == n - 1];
// F(j, 0, n - 1) cout << c[j].id << " \n" [j == n - 1];
int mn = n;
F(j, 0, n - 1) {
if(vst[b[j].id]) continue;
if(mn <= pos2[b[j].id]) ok[b[j].id] = 1;
mn = min(mn, pos2[b[j].id]);
} mn = n;
F(j, 0, n - 1) {
if(vst[c[j].id]) continue;
if(mn <= pos1[c[j].id]) ok[c[j].id] = 1;
mn = min(mn, pos1[c[j].id]);
}
F(j, 0, n - 1) if(! ok[j] && ! vst[j]) res ++;
// cout << res << "\n";
}
cout << res + 1 << "\n";
}
signed main() {
// ios::sync_with_stdio(false);
// cin.tie(0);
sol();
return 0;
}
/*
7
1 4
4 0
2 3
3 1
3 5
0 0
2 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3592kb
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: 0ms
memory: 3812kb
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: 0ms
memory: 3584kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3896kb
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: 3644kb
input:
4 0 0 0 3 3 0 3 3
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Wrong Answer
time: 19ms
memory: 3804kb
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...
output:
3102
result:
wrong answer 1st numbers differ - expected: '718', found: '3102'