QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673032 | #5426. Drain the Water Tank | PDF_vegetable | WA | 2ms | 12144kb | C++14 | 2.7kb | 2024-10-24 20:21:53 | 2024-10-24 20:22:18 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define LL long long
#define MAXN 1000000
#define INF 1000000000000000
#define Pr pair<int,int>
#define X first
#define Y second
LL read(){
LL x=0,F=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*F;
}
int n,pn;
LL nx[MAXN+5],ny[MAXN+5];
int ans;
Pr p[MAXN+5];
int twx[MAXN+5],twy[MAXN+5];
int main(){
n=read();
if(n==3){
puts("1");
return 0;
}
for(int i=0;i<n;i++)
nx[i]=read(),ny[i]=read();
for(int i=0;i<n;i++){
int pre=(i-1+n)%n,suf=(i+1)%n;
if(ny[pre]==ny[i]&&ny[suf]==ny[i])continue;
else if(nx[pre]==nx[i]&&nx[suf]==nx[i])continue;
else p[pn++]=Pr(nx[i],ny[i]);
}
n=pn;
for(int i=0;i<n;i++){
int pre=0,suf=0;
if(p[i].Y==p[(i+1)%n].Y){
pre=(i-1+n)%n;
suf=(i+2)%n;
if(p[i].Y<p[pre].Y&&p[i].Y<p[suf].Y){
twx[i]=1;
//printf("::%d %d\n",p[i].X,p[i].Y);
}
}
else{
pre=(i-1+n)%n;
suf=(i+1)%n;
if(p[i].Y<p[pre].Y&&p[i].Y<p[suf].Y){
twx[i]=1;
//printf("::%d %d\n",p[i].X,p[i].Y);
}
}
if((p[i].X-p[pre].X)*(p[i].X-p[suf].X)>0&&(p[i].Y>min(p[pre].Y,p[suf].Y))){
twy[i]=1;
//printf("**%d %d\n",p[i].X,p[i].Y);
}
}
for(int i=0;i<n;i++)
if(twx[i]){
int j=(i+1)%n;
int cnt=0;
int pre=(i+1)%n,suf=(i-1+n)%n;
if((p[i].X-p[pre].X)*(p[i].X-p[suf].X)>0&&(p[i].Y<=min(p[pre].Y,p[suf].Y))){
cnt=1;
}else{
while(j!=suf){
int ax=p[j].X,ay=p[j].Y;
int bx=p[(j+1)%n].X,by=p[(j+1)%n].Y;
if((ax-p[i].X)*(bx-p[i].X)<0){
//printf("%d %d -> %d %d\n",ax,ay,bx,by);
if(bx<ax){
swap(ax,bx);
swap(ay,by);
}
if((p[i].X-ax)*(p[i].Y-by)-(p[i].X-bx)*(p[i].Y-ay)<0)
cnt++;
}else if(j!=pre&&p[i].X==ax&&p[i].Y<ay){
if(!twy[j])cnt++;
}
j=(j+1)%n;
}
if(p[i].X==p[pre].X)
cnt+=((p[i].X-p[(pre+1)%n].X)*(p[i].X-p[suf].X)>0);
if(p[i].X==p[suf].X)
cnt+=((p[i].X-p[(suf+n-1)%n].X)*(p[i].X-p[pre].X)>0);
}
//printf("::%d %d %d\n",cnt,p[i].X,p[i].Y);
if(cnt%2==1)ans++;
}
printf("%d\n",ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11920kb
input:
6 0 0 1 1 2 1 3 0 3 2 0 2
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 2ms
memory: 12144kb
input:
8 4 4 0 4 0 2 1 2 2 2 2 0 3 0 4 0
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 11992kb
input:
7 1 0 3 4 0 3 1 2 2 3 1 1 0 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 2ms
memory: 11936kb
input:
6 0 0 2 0 1 1 4 1 5 0 3 4
output:
2
result:
ok 1 number(s): "2"
Test #5:
score: 0
Accepted
time: 0ms
memory: 12076kb
input:
8 0 0 1 0 3 -1 3 0 1 1 4 1 5 0 3 4
output:
2
result:
ok 1 number(s): "2"
Test #6:
score: 0
Accepted
time: 0ms
memory: 12076kb
input:
5 0 0 170 0 140 30 60 30 0 70
output:
1
result:
ok 1 number(s): "1"
Test #7:
score: 0
Accepted
time: 0ms
memory: 11984kb
input:
5 0 0 170 0 140 30 60 30 0 100
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 2ms
memory: 12000kb
input:
5 0 0 1 2 1 5 0 2 0 1
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
3 0 0 100 0 0 100
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
3 200 0 100 100 0 0
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
3 50 50 100 50 100 100
output:
1
result:
ok 1 number(s): "1"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
3 3 0 0 4 0 0
output:
1
result:
ok 1 number(s): "1"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3692kb
input:
3 10000 10000 -10000 10000 10000 9999
output:
1
result:
ok 1 number(s): "1"
Test #14:
score: 0
Accepted
time: 0ms
memory: 3496kb
input:
3 10000 10000 -10000 10000 10000 9900
output:
1
result:
ok 1 number(s): "1"
Test #15:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
3 10000 10000 9999 10000 10000 -10000
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
3 0 0 200 0 100 173
output:
1
result:
ok 1 number(s): "1"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
3 0 0 200 0 100 1
output:
1
result:
ok 1 number(s): "1"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
3 -10000 -10000 10000 9999 9999 10000
output:
1
result:
ok 1 number(s): "1"
Test #19:
score: 0
Accepted
time: 0ms
memory: 12016kb
input:
4 10 10 20 10 20 20 10 20
output:
1
result:
ok 1 number(s): "1"
Test #20:
score: 0
Accepted
time: 0ms
memory: 11948kb
input:
4 -10000 -10000 10000 -10000 10000 10000 -10000 10000
output:
1
result:
ok 1 number(s): "1"
Test #21:
score: 0
Accepted
time: 0ms
memory: 12008kb
input:
4 100 0 200 100 100 200 0 100
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 0
Accepted
time: 0ms
memory: 11928kb
input:
4 0 1 100 0 101 100 1 101
output:
1
result:
ok 1 number(s): "1"
Test #23:
score: 0
Accepted
time: 2ms
memory: 11988kb
input:
4 0 0 100 0 100 50 0 50
output:
1
result:
ok 1 number(s): "1"
Test #24:
score: 0
Accepted
time: 0ms
memory: 12076kb
input:
4 0 0 50 0 50 100 0 100
output:
1
result:
ok 1 number(s): "1"
Test #25:
score: 0
Accepted
time: 2ms
memory: 12000kb
input:
4 0 10 10 0 100 90 90 100
output:
1
result:
ok 1 number(s): "1"
Test #26:
score: 0
Accepted
time: 2ms
memory: 12016kb
input:
8 0 100 100 0 250 0 350 100 350 250 250 350 100 350 0 250
output:
1
result:
ok 1 number(s): "1"
Test #27:
score: 0
Accepted
time: 2ms
memory: 11992kb
input:
6 0 50 10 0 70 0 80 10 70 50 50 80
output:
1
result:
ok 1 number(s): "1"
Test #28:
score: 0
Accepted
time: 0ms
memory: 11948kb
input:
4 0 100 0 0 100 0 20 20
output:
1
result:
ok 1 number(s): "1"
Test #29:
score: 0
Accepted
time: 2ms
memory: 11944kb
input:
4 0 100 55 55 100 0 100 100
output:
1
result:
ok 1 number(s): "1"
Test #30:
score: 0
Accepted
time: 0ms
memory: 11984kb
input:
8 0 0 100 0 100 20 40 20 40 40 100 40 100 60 0 60
output:
1
result:
ok 1 number(s): "1"
Test #31:
score: 0
Accepted
time: 2ms
memory: 11948kb
input:
12 0 0 90 0 90 30 40 30 40 40 90 40 90 50 0 50 0 20 50 20 50 10 0 10
output:
1
result:
ok 1 number(s): "1"
Test #32:
score: 0
Accepted
time: 0ms
memory: 12016kb
input:
12 0 0 100 0 100 100 10 100 10 110 200 110 200 60 101 60 101 40 210 40 210 120 0 120
output:
2
result:
ok 1 number(s): "2"
Test #33:
score: 0
Accepted
time: 2ms
memory: 11920kb
input:
10 1000 0 1100 0 1200 100 1220 200 1200 110 1100 10 1000 10 900 110 880 200 900 100
output:
1
result:
ok 1 number(s): "1"
Test #34:
score: 0
Accepted
time: 0ms
memory: 11992kb
input:
16 0 0 60 0 60 70 0 70 0 20 40 20 40 50 20 50 20 40 30 40 30 30 10 30 10 60 50 60 50 10 0 10
output:
2
result:
ok 1 number(s): "2"
Test #35:
score: 0
Accepted
time: 2ms
memory: 11988kb
input:
8 0 1 100 0 5 5 200 5 105 0 205 1 205 10 0 10
output:
2
result:
ok 1 number(s): "2"
Test #36:
score: 0
Accepted
time: 0ms
memory: 11912kb
input:
8 0 1 50 0 5 5 200 5 150 0 205 1 205 10 0 10
output:
2
result:
ok 1 number(s): "2"
Test #37:
score: 0
Accepted
time: 2ms
memory: 12000kb
input:
9 99 100 100 100 99 99 301 99 300 100 301 100 201 274 200 273 199 274
output:
1
result:
ok 1 number(s): "1"
Test #38:
score: 0
Accepted
time: 2ms
memory: 12004kb
input:
15 0 0 10 0 20 0 30 0 40 0 50 0 40 10 30 20 20 30 10 40 0 50 0 40 0 30 0 20 0 10
output:
1
result:
ok 1 number(s): "1"
Test #39:
score: 0
Accepted
time: 0ms
memory: 11992kb
input:
11 0 0 100 0 90 5 80 10 70 15 60 20 50 25 40 20 30 15 20 10 10 5
output:
1
result:
ok 1 number(s): "1"
Test #40:
score: 0
Accepted
time: 2ms
memory: 12080kb
input:
8 0 0 20 30 0 60 0 50 0 40 0 30 0 20 0 10
output:
1
result:
ok 1 number(s): "1"
Test #41:
score: 0
Accepted
time: 2ms
memory: 12076kb
input:
18 0 0 20 0 40 0 60 0 80 0 100 0 120 0 120 30 120 60 120 90 120 120 80 120 40 120 0 120 0 96 0 72 0 48 0 24
output:
1
result:
ok 1 number(s): "1"
Test #42:
score: 0
Accepted
time: 0ms
memory: 12000kb
input:
15 0 0 20 0 40 0 60 0 80 0 100 0 120 0 120 120 80 120 40 120 0 120 0 96 0 72 0 48 0 24
output:
1
result:
ok 1 number(s): "1"
Test #43:
score: 0
Accepted
time: 2ms
memory: 12004kb
input:
11 0 0 20 0 40 0 60 0 80 0 100 0 120 0 120 120 80 120 40 120 0 120
output:
1
result:
ok 1 number(s): "1"
Test #44:
score: 0
Accepted
time: 2ms
memory: 11944kb
input:
9 0 0 20 0 40 0 60 0 80 0 100 0 120 0 120 120 0 120
output:
1
result:
ok 1 number(s): "1"
Test #45:
score: 0
Accepted
time: 1ms
memory: 11872kb
input:
29 0 0 100 0 100 50 0 50 0 20 80 20 80 30 10 30 10 40 20 40 30 40 40 40 50 40 60 40 70 40 80 40 90 40 90 30 90 20 90 10 80 10 70 10 60 10 50 10 40 10 30 10 20 10 10 10 0 10
output:
2
result:
ok 1 number(s): "2"
Test #46:
score: -100
Wrong Answer
time: 0ms
memory: 12004kb
input:
24 0 0 100 0 100 100 200 100 200 0 300 0 300 100 300 200 200 200 200 300 300 300 300 400 300 500 200 500 200 400 100 400 100 500 0 500 0 400 0 300 100 300 100 200 0 200 0 100
output:
1
result:
wrong answer 1st numbers differ - expected: '2', found: '1'