QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#327629 | #833. Cells Blocking | JohnAlfnov | AC ✓ | 233ms | 30560kb | C++14 | 2.0kb | 2024-02-15 11:37:06 | 2024-02-15 11:37:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
char s[3005][3005];
bool vs[3005][3005],vt[3005][3005];
int zx[6005],zd[6005];
int X0[6005],Y0[6005];
int X1[6005],Y1[6005];
int X2[6005],Y2[6005];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
if(s[1][1]=='.')vs[1][1]=1;
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)if(vs[i][j]){
if(s[i+1][j]=='.')vs[i+1][j]=1;
if(s[i][j+1]=='.')vs[i][j+1]=1;
}
int gs=0;
for(int i=1;i<=n;++i)for(int j=1;j<=m;++j){
if(s[i][j]=='.')++gs;
}
if(!vs[n][m]){
printf("%lld\n",1ll*gs*(gs-1)/2);
return 0;
}
if(s[n][m]=='.')vt[n][m]=1;
for(int i=n;i>=1;--i)for(int j=m;j>=1;--j)if(vt[i][j]){
if(s[i-1][j]=='.')vt[i-1][j]=1;
if(s[i][j-1]=='.')vt[i][j-1]=1;
}
int X=1,Y=1;
while(X+Y<n+m){
if(s[X+1][Y]=='.'&&vt[X+1][Y])zx[X+Y]=0,++X;
else zx[X+Y]=1,++Y;
}
X=1,Y=1;
while(X+Y<n+m){
if(s[X][Y+1]=='.'&&vt[X][Y+1])zd[X+Y]=1,++Y;
else zd[X+Y]=0,++X;
}
X0[1]=1,Y0[1]=1;
for(int i=2;i<=n+m-1;++i){
if(zx[i])X0[i]=X0[i-1],Y0[i]=Y0[i-1]+1;
else X0[i]=X0[i-1]+1,Y0[i]=Y0[i-1];
}
X1[1]=1,Y1[1]=1;
for(int i=2;i<=n+m-1;++i){
if(zd[i])X1[i]=X1[i-1],Y1[i]=Y1[i-1]+1;
else X1[i]=X1[i-1]+1,Y1[i]=Y1[i-1];
}
long long ans=0;
X=1,Y=1;
int XX=1,YY=1;
for(int i=1;i<=n+m-1;++i){
int pp=X;
for(int j=X-1;j>=XX;--j){
if(vs[j][i+1-j]&&vt[j][i+1-j]){
pp=j;
break;
}
}
if(pp==X){
ans+=gs-i;
}else{
int X_=pp,Y_=i+1-pp;
while(X_+Y_>2){
X2[X_+Y_-1]=X_,Y2[X_+Y_-1]=Y_;
if(s[X_][Y_-1]=='.'&&vs[X_][Y_-1])--Y_;
else --X_;
}
X2[1]=X_,Y2[1]=Y_;
X_=pp,Y_=i+1-pp;
while(X_+Y_<n+m){
if(s[X_+1][Y_]=='.'&&vt[X_+1][Y_])++X_;
else ++Y_;
X2[X_+Y_-1]=X_,Y2[X_+Y_-1]=Y_;
}
for(int j=1;j<=n+m-1;++j)if(X2[j]==X1[j]&&Y2[j]==Y1[j]){
if(j<=i&&X2[j]==X0[j]&&Y2[j]==Y0[j])continue;
++ans;
}
}
if(zx[i+1])++Y;
else ++X;
if(zd[i+1])++YY;
else ++XX;
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8004kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 1ms
memory: 6036kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5924kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 0ms
memory: 5988kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 0ms
memory: 6000kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 133ms
memory: 30476kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 171ms
memory: 30492kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 188ms
memory: 30560kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 221ms
memory: 30468kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 213ms
memory: 30484kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: 0
Accepted
time: 219ms
memory: 30492kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911522
result:
ok 1 number(s): "17911522"
Test #12:
score: 0
Accepted
time: 211ms
memory: 30488kb
input:
3000 3000 ..............................*................................................................................................................*.....................................................................................................................................................
output:
17892283
result:
ok 1 number(s): "17892283"
Test #13:
score: 0
Accepted
time: 207ms
memory: 30472kb
input:
3000 3000 ................................................................*....*................................................................................................................................................................................*..............................................
output:
17873837
result:
ok 1 number(s): "17873837"
Test #14:
score: 0
Accepted
time: 220ms
memory: 30472kb
input:
3000 3000 ............................................................................................*.............................................................................*.....................................................................................................*....................
output:
17856701
result:
ok 1 number(s): "17856701"
Test #15:
score: 0
Accepted
time: 226ms
memory: 30404kb
input:
3000 3000 ......................................*..........................................................................................................................................................*...................................................................................................
output:
17837857
result:
ok 1 number(s): "17837857"
Test #16:
score: 0
Accepted
time: 222ms
memory: 30496kb
input:
3000 3000 .................................................................................................................................................................................................................................*...................................................................
output:
17819731
result:
ok 1 number(s): "17819731"
Test #17:
score: 0
Accepted
time: 226ms
memory: 30400kb
input:
3000 3000 ......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...
output:
16202000
result:
ok 1 number(s): "16202000"
Test #18:
score: 0
Accepted
time: 233ms
memory: 30400kb
input:
3000 3000 ..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....
output:
21600132
result:
ok 1 number(s): "21600132"
Test #19:
score: 0
Accepted
time: 20ms
memory: 12884kb
input:
3000 3000 ..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......
output:
19862779430431
result:
ok 1 number(s): "19862779430431"
Test #20:
score: 0
Accepted
time: 16ms
memory: 12844kb
input:
3000 3000 .**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....
output:
14601805246666
result:
ok 1 number(s): "14601805246666"
Test #21:
score: 0
Accepted
time: 1ms
memory: 5904kb
input:
1 1 *
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 0ms
memory: 6012kb
input:
1 1 .
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 0ms
memory: 5968kb
input:
2 2 .. ..
output:
6
result:
ok 1 number(s): "6"
Test #24:
score: 0
Accepted
time: 25ms
memory: 14024kb
input:
3000 3000 .***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....
output:
10151159625145
result:
ok 1 number(s): "10151159625145"
Test #25:
score: 0
Accepted
time: 21ms
memory: 13328kb
input:
3000 3000 *******************************************************************************************************************************************************************************************************************************************************.******************************************...
output:
39716328
result:
ok 1 number(s): "39716328"
Test #26:
score: 0
Accepted
time: 199ms
memory: 30404kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
35988321
result:
ok 1 number(s): "35988321"
Test #27:
score: 0
Accepted
time: 193ms
memory: 30492kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35981866
result:
ok 1 number(s): "35981866"
Test #28:
score: 0
Accepted
time: 119ms
memory: 30500kb
input:
3000 3000 ...**................................................................................................................................................................................................................................................................................................
output:
17988153
result:
ok 1 number(s): "17988153"
Test #29:
score: 0
Accepted
time: 126ms
memory: 30464kb
input:
3000 3000 ...*.*...............................................................................................................................................................................................................................................................................................
output:
35969654
result:
ok 1 number(s): "35969654"
Test #30:
score: 0
Accepted
time: 197ms
memory: 30492kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
17982216
result:
ok 1 number(s): "17982216"
Test #31:
score: 0
Accepted
time: 181ms
memory: 30476kb
input:
3000 3000 ....**.*.............................................................................................................................................................................................................................................................................................
output:
71916090
result:
ok 1 number(s): "71916090"
Test #32:
score: 0
Accepted
time: 175ms
memory: 30468kb
input:
3000 3000 ....****.............................................................................................................................................................................................................................................................................................
output:
71903186
result:
ok 1 number(s): "71903186"
Test #33:
score: 0
Accepted
time: 180ms
memory: 30496kb
input:
3000 3000 .........*...........................................................................................................................................................................................................................................................................................
output:
17973051
result:
ok 1 number(s): "17973051"
Test #34:
score: 0
Accepted
time: 189ms
memory: 30412kb
input:
3000 3000 .*.......*.............................................................................................................*................................................................................*............................................................................................
output:
35630636
result:
ok 1 number(s): "35630636"
Test #35:
score: 0
Accepted
time: 176ms
memory: 30556kb
input:
3000 3000 .**...........................*..........................................................................................................................................*...........................................................................................................................
output:
44529907
result:
ok 1 number(s): "44529907"
Test #36:
score: 0
Accepted
time: 201ms
memory: 30528kb
input:
3000 3000 ....*................................................................................................................................................................................................................................................................................................
output:
53426863
result:
ok 1 number(s): "53426863"
Test #37:
score: 0
Accepted
time: 167ms
memory: 30560kb
input:
3000 3000 ..*.*........................................................................*............................*...............*.............................................................................................................................................*........*...................
output:
53419301
result:
ok 1 number(s): "53419301"
Test #38:
score: 0
Accepted
time: 208ms
memory: 30476kb
input:
3000 3000 ......*.........*...................................................................................*.....................................................................................................................*................................................*.........................
output:
26705269
result:
ok 1 number(s): "26705269"
Test #39:
score: 0
Accepted
time: 197ms
memory: 30448kb
input:
3000 3000 ....*.**....*................*............................*..........*...............................................................................................................................................................................................................................
output:
17799069
result:
ok 1 number(s): "17799069"
Test #40:
score: 0
Accepted
time: 205ms
memory: 30492kb
input:
3000 3000 ...***.......................................*...........*.....................*........*...........................................................................................................................................................*................................................
output:
53393629
result:
ok 1 number(s): "53393629"
Test #41:
score: 0
Accepted
time: 187ms
memory: 30368kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
98852811
result:
ok 1 number(s): "98852811"
Test #42:
score: 0
Accepted
time: 1ms
memory: 8056kb
input:
1 3000 ........................................................................................................................................................................................................................................................................................................
output:
4498500
result:
ok 1 number(s): "4498500"
Test #43:
score: 0
Accepted
time: 170ms
memory: 30492kb
input:
3000 3000 .*.....*...........................................................................................................*...................................*........................................................................................*............*.......................................
output:
88979547
result:
ok 1 number(s): "88979547"
Test #44:
score: 0
Accepted
time: 198ms
memory: 30560kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35964327
result:
ok 1 number(s): "35964327"