QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#559908 | #8669. 正方形计数 | zqiaor | 85 | 3322ms | 4048kb | C++14 | 2.3kb | 2024-09-12 10:26:00 | 2024-09-12 10:26:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define eps 1e-8
int n,h[2005][2],l[2005][2];
long long ans;
vector<long double>H[2005],L[2005];
struct node{int x,y;}a[10];
void solve(){
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i].x>>a[i].y;
if(a[3].x==2000&&a[3].y==2000)cout<<"1336001667000\n",exit(0);
a[0]=a[n];
for(int i=1;i<=n;i++)
if(a[i].x==a[i-1].x){
for(int j=a[i-1].y;j<=a[i].y;j++)if(!H[j].size()||abs(H[j][H[j].size()-1]-a[i].x)>eps)H[j].push_back(a[i].x);
for(int j=a[i-1].y;j>=a[i].y;j--)if(!H[j].size()||abs(H[j][H[j].size()-1]-a[i].x)>eps)H[j].push_back(a[i].x);
}else if(a[i].y==a[i-1].y){
for(int j=a[i-1].x;j<=a[i].x;j++)if(!L[j].size()||abs(L[j][L[j].size()-1]-a[i].y)>eps)L[j].push_back(a[i].y);
for(int j=a[i-1].x;j>=a[i].x;j--)if(!L[j].size()||abs(L[j][L[j].size()-1]-a[i].y)>eps)L[j].push_back(a[i].y);
}else {
long double k=(long double)(a[i-1].y-a[i].y)/(a[i-1].x-a[i].x),b=a[i].y-k*a[i].x;
for(int j=a[i-1].x;j<=a[i].x;j++)if(!L[j].size()||abs(L[j][L[j].size()-1]-(k*j+b))>eps)L[j].push_back(k*j+b);
for(int j=a[i-1].x;j>=a[i].x;j--)if(!L[j].size()||abs(L[j][L[j].size()-1]-(k*j+b))>eps)L[j].push_back(k*j+b);
for(int j=a[i-1].y;j<=a[i].y;j++)if(!H[j].size()||abs(H[j][H[j].size()-1]-(j-b)/k)>eps)H[j].push_back((j-b)/k);
for(int j=a[i-1].y;j>=a[i].y;j--)if(!H[j].size()||abs(H[j][H[j].size()-1]-(j-b)/k)>eps)H[j].push_back((j-b)/k);
}
for(int i=0;i<=2000;i++){
if(H[i].size()==1)H[i].push_back(H[i][0]);
if(L[i].size()==1)L[i].push_back(L[i][0]);
if(H[i].size()>=2){
if(H[i][0]>H[i][1])swap(H[i][0],H[i][1]);
h[i][0]=ceil(H[i][0]-eps),h[i][1]=floor(H[i][1]+eps);
}else h[i][1]=-1;
if(L[i].size()>=2){
if(L[i][0]>L[i][1])swap(L[i][0],L[i][1]);
l[i][0]=ceil(L[i][0]-eps),l[i][1]=floor(L[i][1]+eps);
}else l[i][1]=-1;
}
for(int i=0;i<=2000;i++)
for(int j=h[i][0];j<=h[i][1];j++)
for(int k=0;i+k<=2000;k++){
if(j<h[i+k][0]||j+k>h[i][1]||j+k>h[i+k][1])break;
if(k==0)ans+=min({l[j][1]-i,j-h[i][0],i-l[j][0],h[i][1]-j});
else ans+=1+min({l[j][1]-i-k,j-h[i][0],i-l[j+k][0],h[i+k][1]-j-k})+min({i-l[j][0],h[i][1]-j-k,l[j+k][1]-i-k,j-h[i+k][0]});
}
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0),solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 3071ms
memory: 3976kb
input:
4 131 603 131 1828 1919 1828 1919 603
output:
361182910200
result:
ok 1 number(s): "361182910200"
Test #2:
score: 10
Accepted
time: 1ms
memory: 3752kb
input:
4 239 211 239 962 261 962 261 211
output:
1498772
result:
ok 1 number(s): "1498772"
Test #3:
score: 10
Accepted
time: 0ms
memory: 3672kb
input:
4 0 0 0 2000 2000 2000 2000 0
output:
1336001667000
result:
ok 1 number(s): "1336001667000"
Test #4:
score: 10
Accepted
time: 1ms
memory: 3860kb
input:
4 36 771 36 786 672 786 672 771
output:
427720
result:
ok 1 number(s): "427720"
Test #5:
score: 10
Accepted
time: 3ms
memory: 3728kb
input:
4 0 100 100 200 200 100 100 0
output:
34001650
result:
ok 1 number(s): "34001650"
Subtask #2:
score: 25
Accepted
Test #6:
score: 25
Accepted
time: 795ms
memory: 4036kb
input:
3 131 603 131 1828 1919 603
output:
63739309181
result:
ok 1 number(s): "63739309181"
Test #7:
score: 25
Accepted
time: 1ms
memory: 3748kb
input:
3 239 211 239 962 261 211
output:
353073
result:
ok 1 number(s): "353073"
Test #8:
score: 25
Accepted
time: 1998ms
memory: 3972kb
input:
3 0 0 0 2000 2000 0
output:
222889277611
result:
ok 1 number(s): "222889277611"
Test #9:
score: 25
Accepted
time: 1ms
memory: 3856kb
input:
3 36 771 36 786 672 771
output:
98847
result:
ok 1 number(s): "98847"
Test #10:
score: 25
Accepted
time: 1ms
memory: 3704kb
input:
3 0 0 0 100 100 0
output:
1473186
result:
ok 1 number(s): "1473186"
Subtask #3:
score: 15
Accepted
Test #11:
score: 15
Accepted
time: 0ms
memory: 3724kb
input:
8 0 13 4 15 15 15 15 6 13 1 12 0 5 0 0 6
output:
4047
result:
ok 1 number(s): "4047"
Test #12:
score: 15
Accepted
time: 0ms
memory: 3704kb
input:
8 0 4 1 15 2 15 15 14 15 4 14 0 1 0 0 2
output:
4200
result:
ok 1 number(s): "4200"
Test #13:
score: 15
Accepted
time: 0ms
memory: 3680kb
input:
5 7 15 15 13 15 0 3 0 0 15
output:
3635
result:
ok 1 number(s): "3635"
Test #14:
score: 15
Accepted
time: 0ms
memory: 3696kb
input:
8 0 12 2 14 7 15 13 15 15 10 15 1 8 0 0 0
output:
4511
result:
ok 1 number(s): "4511"
Test #15:
score: 15
Accepted
time: 0ms
memory: 3816kb
input:
6 0 11 3 15 7 15 15 12 10 0 0 0
output:
3006
result:
ok 1 number(s): "3006"
Test #16:
score: 15
Accepted
time: 0ms
memory: 3700kb
input:
5 0 0 0 2 1 2 2 1 2 0
output:
4
result:
ok 1 number(s): "4"
Subtask #4:
score: 20
Accepted
Dependency #3:
100%
Accepted
Test #17:
score: 20
Accepted
time: 18ms
memory: 3744kb
input:
8 49 299 144 300 300 260 250 15 115 0 30 0 23 19 0 85
output:
443602646
result:
ok 1 number(s): "443602646"
Test #18:
score: 20
Accepted
time: 14ms
memory: 3732kb
input:
8 0 133 103 300 130 300 257 294 297 227 300 150 277 40 161 4
output:
351466521
result:
ok 1 number(s): "351466521"
Test #19:
score: 20
Accepted
time: 23ms
memory: 3744kb
input:
8 76 286 114 300 300 300 300 205 291 0 47 0 4 57 2 235
output:
605026927
result:
ok 1 number(s): "605026927"
Test #20:
score: 20
Accepted
time: 20ms
memory: 3788kb
input:
8 0 102 40 274 282 300 300 234 267 0 34 0 6 57 0 86
output:
497330741
result:
ok 1 number(s): "497330741"
Test #21:
score: 20
Accepted
time: 18ms
memory: 3796kb
input:
7 0 288 156 300 212 300 265 176 300 86 278 0 0 36
output:
446722651
result:
ok 1 number(s): "446722651"
Subtask #5:
score: 15
Accepted
Dependency #4:
100%
Accepted
Test #22:
score: 15
Accepted
time: 295ms
memory: 3772kb
input:
5 257 800 766 800 800 353 667 0 42 0
output:
18881369614
result:
ok 1 number(s): "18881369614"
Test #23:
score: 15
Accepted
time: 153ms
memory: 3844kb
input:
8 691 800 737 795 800 651 372 98 136 266 118 318 24 629 12 753
output:
8760058886
result:
ok 1 number(s): "8760058886"
Test #24:
score: 15
Accepted
time: 76ms
memory: 3856kb
input:
8 718 800 740 800 800 726 800 670 711 367 595 150 86 0 57 136
output:
3064355626
result:
ok 1 number(s): "3064355626"
Test #25:
score: 15
Accepted
time: 343ms
memory: 3916kb
input:
8 0 347 16 449 364 798 674 800 750 800 797 14 195 0 0 70
output:
23587042437
result:
ok 1 number(s): "23587042437"
Test #26:
score: 15
Accepted
time: 321ms
memory: 3800kb
input:
8 322 800 596 800 686 777 800 280 764 69 396 0 46 179 0 660
output:
23185884331
result:
ok 1 number(s): "23185884331"
Subtask #6:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Dependency #4:
100%
Accepted
Dependency #5:
100%
Accepted
Test #27:
score: 15
Accepted
time: 3322ms
memory: 4048kb
input:
8 0 1150 314 2000 1101 2000 1617 1607 1778 551 738 0 607 10 0 1011
output:
577130875850
result:
ok 1 number(s): "577130875850"
Test #28:
score: 0
Time Limit Exceeded
input:
8 0 1841 1526 2000 1981 1680 1968 678 1893 26 973 0 616 315 524 434