QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#328374 | #833. Cells Blocking | thomaswmy | AC ✓ | 139ms | 118580kb | C++14 | 2.2kb | 2024-02-15 19:45:40 | 2024-02-15 19:45:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3010;
int n,m;
char S[N][N];
bool f[N][N],g[N][N];
bool p1[N][N],p2[N][N];
int cl[N][N],cr[N][N];
int ld[N<<1];
int cnt,tot;
ll ans;
int main() {
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) {
scanf("%s",S[i]+1);
for(int j=1;j<=m;j++) cnt+=S[i][j]=='.';
}
if(cnt<=1) {
printf("0");
return 0;
}
f[1][1]=1;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
if(S[i][j]!='.') f[i][j]=0;
if(j<m) f[i][j+1]|=f[i][j];
if(i<n) f[i+1][j]|=f[i][j];
}
}
g[n][m]=1;
for(int i=n;i>=1;i--) {
for(int j=m;j>=1;j--) {
if(S[i][j]!='.') g[i][j]=0;
if(j>1) g[i][j-1]|=g[i][j];
if(i>1) g[i-1][j]|=g[i][j];
}
}
if(!f[n][m]) {
printf("%lld",1ll*cnt*(cnt-1)/2);
return 0;
}
int x=1,y=1;
while(x!=n || y!=m) {
p1[x][y]=1;
if(x==n) y++;
else if(y==m) x++;
else if(f[x+1][y] && g[x+1][y]) x++;
else y++;
}
p1[x][y]=1;
x=1,y=1;
while(x!=n || y!=m) {
p2[x][y]=1;
if(x==n) y++;
else if(y==m) x++;
else if(f[x][y+1] && g[x][y+1]) y++;
else x++;
}
p2[x][y]=1;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) tot+=p1[i][j]&p2[i][j];
ans=1ll*tot*(cnt-tot)+1ll*tot*(tot-1)/2;
for(int i=n;i>=1;i--) {
for(int j=m;j>=1;j--) {
if(!f[i][j] || !g[i][j]) continue;
cr[i][j]=p1[i][j];
if(i==n && j==m) continue;
else if(i==n) cr[i][j]+=cr[i][j+1];
else if(j==m) cr[i][j]+=cr[i+1][j];
else if(f[i][j+1] && g[i][j+1]) cr[i][j]+=cr[i][j+1];
else cr[i][j]+=cr[i+1][j];
}
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
if(!f[i][j] || !g[i][j]) continue;
cl[i][j]=p1[i][j];
if(i==1 && j==1) continue;
else if(i==1) cl[i][j]+=cl[i][j-1];
else if(j==1) cl[i][j]+=cl[i-1][j];
else if(f[i-1][j] && g[i-1][j]) cl[i][j]+=cl[i-1][j];
else cl[i][j]+=cl[i][j-1];
}
}
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(f[i][j] && g[i][j]) if(!ld[i+j] && !p2[i][j]) ld[i+j]=i;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
if(p1[i][j]) continue;
if(p2[i][j]) {
int x=ld[i+j],y=i+j-x;
ans+=cl[x][y]+cr[x][y]-p1[x][y]-tot;
}
}
}
printf("%lld",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4032kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3776kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3984kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 112ms
memory: 118572kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 101ms
memory: 118512kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 97ms
memory: 118528kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 97ms
memory: 118480kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 100ms
memory: 118464kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: 0
Accepted
time: 98ms
memory: 118232kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911522
result:
ok 1 number(s): "17911522"
Test #12:
score: 0
Accepted
time: 108ms
memory: 118280kb
input:
3000 3000 ..............................*................................................................................................................*.....................................................................................................................................................
output:
17892283
result:
ok 1 number(s): "17892283"
Test #13:
score: 0
Accepted
time: 92ms
memory: 118328kb
input:
3000 3000 ................................................................*....*................................................................................................................................................................................*..............................................
output:
17873837
result:
ok 1 number(s): "17873837"
Test #14:
score: 0
Accepted
time: 104ms
memory: 118184kb
input:
3000 3000 ............................................................................................*.............................................................................*.....................................................................................................*....................
output:
17856701
result:
ok 1 number(s): "17856701"
Test #15:
score: 0
Accepted
time: 84ms
memory: 118284kb
input:
3000 3000 ......................................*..........................................................................................................................................................*...................................................................................................
output:
17837857
result:
ok 1 number(s): "17837857"
Test #16:
score: 0
Accepted
time: 88ms
memory: 118312kb
input:
3000 3000 .................................................................................................................................................................................................................................*...................................................................
output:
17819731
result:
ok 1 number(s): "17819731"
Test #17:
score: 0
Accepted
time: 122ms
memory: 114756kb
input:
3000 3000 ......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...
output:
16202000
result:
ok 1 number(s): "16202000"
Test #18:
score: 0
Accepted
time: 139ms
memory: 106280kb
input:
3000 3000 ..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....
output:
21600132
result:
ok 1 number(s): "21600132"
Test #19:
score: 0
Accepted
time: 71ms
memory: 30332kb
input:
3000 3000 ..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......
output:
19862779430431
result:
ok 1 number(s): "19862779430431"
Test #20:
score: 0
Accepted
time: 93ms
memory: 30172kb
input:
3000 3000 .**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....
output:
14601805246666
result:
ok 1 number(s): "14601805246666"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
1 1 *
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
1 1 .
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
2 2 .. ..
output:
6
result:
ok 1 number(s): "6"
Test #24:
score: 0
Accepted
time: 101ms
memory: 30336kb
input:
3000 3000 .***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....
output:
10151159625145
result:
ok 1 number(s): "10151159625145"
Test #25:
score: 0
Accepted
time: 24ms
memory: 30208kb
input:
3000 3000 *******************************************************************************************************************************************************************************************************************************************************.******************************************...
output:
39716328
result:
ok 1 number(s): "39716328"
Test #26:
score: 0
Accepted
time: 104ms
memory: 118540kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
35988321
result:
ok 1 number(s): "35988321"
Test #27:
score: 0
Accepted
time: 104ms
memory: 118384kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35981866
result:
ok 1 number(s): "35981866"
Test #28:
score: 0
Accepted
time: 108ms
memory: 118520kb
input:
3000 3000 ...**................................................................................................................................................................................................................................................................................................
output:
17988153
result:
ok 1 number(s): "17988153"
Test #29:
score: 0
Accepted
time: 99ms
memory: 118440kb
input:
3000 3000 ...*.*...............................................................................................................................................................................................................................................................................................
output:
35969654
result:
ok 1 number(s): "35969654"
Test #30:
score: 0
Accepted
time: 97ms
memory: 118488kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
17982216
result:
ok 1 number(s): "17982216"
Test #31:
score: 0
Accepted
time: 115ms
memory: 118380kb
input:
3000 3000 ....**.*.............................................................................................................................................................................................................................................................................................
output:
71916090
result:
ok 1 number(s): "71916090"
Test #32:
score: 0
Accepted
time: 102ms
memory: 118340kb
input:
3000 3000 ....****.............................................................................................................................................................................................................................................................................................
output:
71903186
result:
ok 1 number(s): "71903186"
Test #33:
score: 0
Accepted
time: 102ms
memory: 118532kb
input:
3000 3000 .........*...........................................................................................................................................................................................................................................................................................
output:
17973051
result:
ok 1 number(s): "17973051"
Test #34:
score: 0
Accepted
time: 99ms
memory: 118204kb
input:
3000 3000 .*.......*.............................................................................................................*................................................................................*............................................................................................
output:
35630636
result:
ok 1 number(s): "35630636"
Test #35:
score: 0
Accepted
time: 103ms
memory: 118148kb
input:
3000 3000 .**...........................*..........................................................................................................................................*...........................................................................................................................
output:
44529907
result:
ok 1 number(s): "44529907"
Test #36:
score: 0
Accepted
time: 99ms
memory: 118496kb
input:
3000 3000 ....*................................................................................................................................................................................................................................................................................................
output:
53426863
result:
ok 1 number(s): "53426863"
Test #37:
score: 0
Accepted
time: 107ms
memory: 118364kb
input:
3000 3000 ..*.*........................................................................*............................*...............*.............................................................................................................................................*........*...................
output:
53419301
result:
ok 1 number(s): "53419301"
Test #38:
score: 0
Accepted
time: 110ms
memory: 118368kb
input:
3000 3000 ......*.........*...................................................................................*.....................................................................................................................*................................................*.........................
output:
26705269
result:
ok 1 number(s): "26705269"
Test #39:
score: 0
Accepted
time: 94ms
memory: 118312kb
input:
3000 3000 ....*.**....*................*............................*..........*...............................................................................................................................................................................................................................
output:
17799069
result:
ok 1 number(s): "17799069"
Test #40:
score: 0
Accepted
time: 88ms
memory: 118128kb
input:
3000 3000 ...***.......................................*...........*.....................*........*...........................................................................................................................................................*................................................
output:
53393629
result:
ok 1 number(s): "53393629"
Test #41:
score: 0
Accepted
time: 103ms
memory: 118580kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
98852811
result:
ok 1 number(s): "98852811"
Test #42:
score: 0
Accepted
time: 1ms
memory: 3940kb
input:
1 3000 ........................................................................................................................................................................................................................................................................................................
output:
4498500
result:
ok 1 number(s): "4498500"
Test #43:
score: 0
Accepted
time: 92ms
memory: 118436kb
input:
3000 3000 .*.....*...........................................................................................................*...................................*........................................................................................*............*.......................................
output:
88979547
result:
ok 1 number(s): "88979547"
Test #44:
score: 0
Accepted
time: 122ms
memory: 118484kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35964327
result:
ok 1 number(s): "35964327"