QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#561308 | #7906. Almost Convex | cyc_43346 | WA | 396ms | 4224kb | C++14 | 1.8kb | 2024-09-12 21:44:50 | 2024-09-12 21:44:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int n,ans,v[2100],st[2100],tp;
struct point {
LL x,y; int id;
double ang;
point operator-(const point& p) const {
return (point){x-p.x,y-p.y,0,0};
}
}p[2100],pp[2100];
LL dis(point p1,point p2) {
return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
bool cmp(point x,point y)
{
if(x.ang==y.ang) return dis(x,p[1])<dis(y,p[1]);
return x.ang<y.ang;
}
LL cross(point x,point y) {
return x.x*y.y-x.y*y.x;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>p[i].x>>p[i].y;
for(int i=2;i<=n;i++) {
if(p[i].y<p[1].y||(p[i].y==p[1].y&&p[i].x<p[1].x)) swap(p[1],p[i]);
}
for(int i=2;i<=n;i++) {
p[i].ang=atan2(p[i].y-p[1].y,p[i].x-p[1].x);
}
sort(p+2,p+n+1,cmp);
for(int i=1;i<=n;i++) p[i].id=i;
st[++tp]=1;
for(int i=2;i<=n;i++) {
while(tp>=2&&cross(p[st[tp]]-p[st[tp-1]],p[i]-p[st[tp]])<0) --tp;
st[++tp]=i;
}
for(int i=1;i<=tp;i++) v[st[i]]=1;
for(int i=1;i<=n;i++) pp[i]=p[i];
for(int i=1;i<=n;i++) {
if(v[i]) continue;
for(int j=1;j<=n;j++) p[j]=pp[j];
swap(p[1],p[i]);
for(int j=2;j<=n;j++) p[j].ang=atan2(p[j].y-p[1].y,p[j].x-p[1].x);
sort(p+2,p+n+1,cmp);
int sta=2;
while(!v[p[sta].id]) ++sta;
for(int j=2;j<n;j++) {
int nxt=j+1;
while(nxt<n&&p[nxt+1].ang==p[j+1].ang&&!v[p[nxt].id]) ++nxt;
if(v[p[j].id]&&v[p[nxt].id]) ++ans;
j=nxt-1;
}
if(v[p[n].id]&&v[p[sta].id]) ++ans;
}
cout<<ans+1<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4008kb
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: 4096kb
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: 3824kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3984kb
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: 3952kb
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: 396ms
memory: 4224kb
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:
827
result:
wrong answer 1st numbers differ - expected: '718', found: '827'