QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#546532 | #833. Cells Blocking | liuhengxi | AC ✓ | 65ms | 89956kb | C++14 | 2.9kb | 2024-09-04 08:35:08 | 2024-09-04 08:35:08 |
Judging History
answer
// created: 2024-09-03 15:53:57
#include<cstdio>
#include<cctype>
#include<algorithm>
#define F(i,l,r) for(int i=(l),i##_end=(r);i<i##_end;++i)
#define I128 //||is_same<T,__int128_t>::value||is_same<T,__uint128_t>::value
using namespace std;
template<typename T>enable_if_t<is_integral<T>::value I128,void> readmain(T &x)
{
bool neg=false;int c=getchar();
for(;!isdigit(c);c=getchar())if(c=='-')neg=true;
for(x=0;isdigit(c);c=getchar())x=(T)(10*x+(c-'0'));
if(neg)x=-x;
}
template<typename T>T& read(T &x){readmain(x);return x;}
template<typename T,typename ...Tr>void read(T &x,Tr&... r){readmain(x);read(r...);}
typedef long long ll;
constexpr int N=3005;
struct pos2d
{
int x,y;
};
int n,m,len,fa[N][N],fb[N][N],laa[2*N],lab[2*N],lba[2*N],lbb[2*N];
ll ans;
pos2d a[2*N],b[2*N];
char s[N][N],f[N][N];
int main()
{
read(n,m);
F(i,0,n)scanf("%s",s[i]);
int t0=0;
F(i,0,n)F(j,0,m)t0+=s[i][j]=s[i][j]=='.';
f[0][0]=s[0][0];
F(i,1,n)f[i][0]=f[i-1][0]&s[i][0];
F(i,1,m)f[0][i]=f[0][i-1]&s[0][i];
F(i,1,n)F(j,1,m)f[i][j]=(f[i-1][j]|f[i][j-1])&s[i][j];
if(!f[n-1][m-1])return printf("%lld\n",t0*(t0-1ll)>>1),0;
len=n+m-1;
for(int i=len-1,x=n-1,y=m-1;;)
{
a[i]={x,y};
s[x][y]=2;
if(!~--i)break;
if(y&&(!x||f[x][y-1]))--y;
else --x;
}
for(int i=len-1,x=n-1,y=m-1;;)
{
b[i]={x,y};
s[x][y]=2;
if(!~--i)break;
if(x&&(!y||f[x-1][y]))--x;
else --y;
}
int l=0,t1=1;
F(r,1,len)
{
if(a[r].x!=b[r].x)continue;
int lx=a[l].x,ly=a[l].y,rx=a[r].x,ry=a[r].y;
F(i,lx,rx+1)F(j,ly,ry+1)fa[i][j]=fb[i][j]=-1;
F(i,l,r+1)fa[a[i].x][a[i].y]=i,fb[b[i].x][b[i].y]=i;
for(int i=rx;--i>=lx;)for(int j=ry;--j>=ly;)if(s[i][j]==1)
{
fa[i][j]=max(fa[i][j],fa[i][j+1]);
fa[i][j]=max(fa[i][j],fa[i+1][j]);
fb[i][j]=max(fb[i][j],fb[i][j+1]);
fb[i][j]=max(fb[i][j],fb[i+1][j]);
}
F(i,l,r)
{
if(a[i].x<rx)fa[a[i].x][a[i].y]=max(fa[a[i].x][a[i].y],fa[a[i].x+1][a[i].y]);
if(a[i].y<ry)fa[a[i].x][a[i].y]=max(fa[a[i].x][a[i].y],fa[a[i].x][a[i].y+1]);
if(b[i].x<rx)fa[b[i].x][b[i].y]=max(fa[b[i].x][b[i].y],fa[b[i].x+1][b[i].y]);
if(b[i].y<ry)fa[b[i].x][b[i].y]=max(fa[b[i].x][b[i].y],fa[b[i].x][b[i].y+1]);
if(a[i].x<rx)fb[a[i].x][a[i].y]=max(fb[a[i].x][a[i].y],fb[a[i].x+1][a[i].y]);
if(a[i].y<ry)fb[a[i].x][a[i].y]=max(fb[a[i].x][a[i].y],fb[a[i].x][a[i].y+1]);
if(b[i].x<rx)fb[b[i].x][b[i].y]=max(fb[b[i].x][b[i].y],fb[b[i].x+1][b[i].y]);
if(b[i].y<ry)fb[b[i].x][b[i].y]=max(fb[b[i].x][b[i].y],fb[b[i].x][b[i].y+1]);
}
F(i,l,r+1)laa[i]=fa[a[i].x][a[i].y],lab[i]=fa[b[i].x][b[i].y],lba[i]=fb[a[i].x][a[i].y],lbb[i]=fb[b[i].x][b[i].y];
F(i,l+1,r+1)laa[i]=max(laa[i],laa[i-1]),lba[i]=max(lba[i],lba[i-1]),lab[i]=max(lab[i],lab[i-1]),lbb[i]=max(lbb[i],lbb[i-1]);
F(i,l+1,r)if(laa[i-1]<=i)F(j,l+1,r)if(lbb[j-1]<=j&&lba[i-1]<=j&&lab[j-1]<=i)++ans;
++t1;
l=r;
}
ans+=t1*(2ll*t0-t1-1)>>1;
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: 7780kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7696kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3660kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3604kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 51ms
memory: 89936kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 55ms
memory: 89860kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 53ms
memory: 89864kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 54ms
memory: 89940kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 50ms
memory: 89856kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: 0
Accepted
time: 49ms
memory: 89848kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911522
result:
ok 1 number(s): "17911522"
Test #12:
score: 0
Accepted
time: 57ms
memory: 89848kb
input:
3000 3000 ..............................*................................................................................................................*.....................................................................................................................................................
output:
17892283
result:
ok 1 number(s): "17892283"
Test #13:
score: 0
Accepted
time: 54ms
memory: 89856kb
input:
3000 3000 ................................................................*....*................................................................................................................................................................................*..............................................
output:
17873837
result:
ok 1 number(s): "17873837"
Test #14:
score: 0
Accepted
time: 61ms
memory: 89848kb
input:
3000 3000 ............................................................................................*.............................................................................*.....................................................................................................*....................
output:
17856701
result:
ok 1 number(s): "17856701"
Test #15:
score: 0
Accepted
time: 55ms
memory: 89956kb
input:
3000 3000 ......................................*..........................................................................................................................................................*...................................................................................................
output:
17837857
result:
ok 1 number(s): "17837857"
Test #16:
score: 0
Accepted
time: 65ms
memory: 89940kb
input:
3000 3000 .................................................................................................................................................................................................................................*...................................................................
output:
17819731
result:
ok 1 number(s): "17819731"
Test #17:
score: 0
Accepted
time: 56ms
memory: 89928kb
input:
3000 3000 ......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...
output:
16202000
result:
ok 1 number(s): "16202000"
Test #18:
score: 0
Accepted
time: 54ms
memory: 89856kb
input:
3000 3000 ..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....
output:
21600132
result:
ok 1 number(s): "21600132"
Test #19:
score: 0
Accepted
time: 25ms
memory: 19420kb
input:
3000 3000 ..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......
output:
19862779430431
result:
ok 1 number(s): "19862779430431"
Test #20:
score: 0
Accepted
time: 17ms
memory: 19440kb
input:
3000 3000 .**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....
output:
14601805246666
result:
ok 1 number(s): "14601805246666"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
1 1 *
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 1ms
memory: 5672kb
input:
1 1 .
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 1ms
memory: 7732kb
input:
2 2 .. ..
output:
6
result:
ok 1 number(s): "6"
Test #24:
score: 0
Accepted
time: 26ms
memory: 20928kb
input:
3000 3000 .***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....
output:
10151159625145
result:
ok 1 number(s): "10151159625145"
Test #25:
score: 0
Accepted
time: 26ms
memory: 21164kb
input:
3000 3000 *******************************************************************************************************************************************************************************************************************************************************.******************************************...
output:
39716328
result:
ok 1 number(s): "39716328"
Test #26:
score: 0
Accepted
time: 60ms
memory: 89772kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
35988321
result:
ok 1 number(s): "35988321"
Test #27:
score: 0
Accepted
time: 55ms
memory: 89920kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35981866
result:
ok 1 number(s): "35981866"
Test #28:
score: 0
Accepted
time: 51ms
memory: 89920kb
input:
3000 3000 ...**................................................................................................................................................................................................................................................................................................
output:
17988153
result:
ok 1 number(s): "17988153"
Test #29:
score: 0
Accepted
time: 50ms
memory: 89840kb
input:
3000 3000 ...*.*...............................................................................................................................................................................................................................................................................................
output:
35969654
result:
ok 1 number(s): "35969654"
Test #30:
score: 0
Accepted
time: 53ms
memory: 89944kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
17982216
result:
ok 1 number(s): "17982216"
Test #31:
score: 0
Accepted
time: 47ms
memory: 89912kb
input:
3000 3000 ....**.*.............................................................................................................................................................................................................................................................................................
output:
71916090
result:
ok 1 number(s): "71916090"
Test #32:
score: 0
Accepted
time: 55ms
memory: 89860kb
input:
3000 3000 ....****.............................................................................................................................................................................................................................................................................................
output:
71903186
result:
ok 1 number(s): "71903186"
Test #33:
score: 0
Accepted
time: 58ms
memory: 89848kb
input:
3000 3000 .........*...........................................................................................................................................................................................................................................................................................
output:
17973051
result:
ok 1 number(s): "17973051"
Test #34:
score: 0
Accepted
time: 53ms
memory: 89924kb
input:
3000 3000 .*.......*.............................................................................................................*................................................................................*............................................................................................
output:
35630636
result:
ok 1 number(s): "35630636"
Test #35:
score: 0
Accepted
time: 41ms
memory: 89916kb
input:
3000 3000 .**...........................*..........................................................................................................................................*...........................................................................................................................
output:
44529907
result:
ok 1 number(s): "44529907"
Test #36:
score: 0
Accepted
time: 52ms
memory: 89936kb
input:
3000 3000 ....*................................................................................................................................................................................................................................................................................................
output:
53426863
result:
ok 1 number(s): "53426863"
Test #37:
score: 0
Accepted
time: 65ms
memory: 89920kb
input:
3000 3000 ..*.*........................................................................*............................*...............*.............................................................................................................................................*........*...................
output:
53419301
result:
ok 1 number(s): "53419301"
Test #38:
score: 0
Accepted
time: 50ms
memory: 89920kb
input:
3000 3000 ......*.........*...................................................................................*.....................................................................................................................*................................................*.........................
output:
26705269
result:
ok 1 number(s): "26705269"
Test #39:
score: 0
Accepted
time: 50ms
memory: 89876kb
input:
3000 3000 ....*.**....*................*............................*..........*...............................................................................................................................................................................................................................
output:
17799069
result:
ok 1 number(s): "17799069"
Test #40:
score: 0
Accepted
time: 53ms
memory: 89908kb
input:
3000 3000 ...***.......................................*...........*.....................*........*...........................................................................................................................................................*................................................
output:
53393629
result:
ok 1 number(s): "53393629"
Test #41:
score: 0
Accepted
time: 51ms
memory: 89900kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
98852811
result:
ok 1 number(s): "98852811"
Test #42:
score: 0
Accepted
time: 1ms
memory: 7740kb
input:
1 3000 ........................................................................................................................................................................................................................................................................................................
output:
4498500
result:
ok 1 number(s): "4498500"
Test #43:
score: 0
Accepted
time: 45ms
memory: 89896kb
input:
3000 3000 .*.....*...........................................................................................................*...................................*........................................................................................*............*.......................................
output:
88979547
result:
ok 1 number(s): "88979547"
Test #44:
score: 0
Accepted
time: 51ms
memory: 89948kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35964327
result:
ok 1 number(s): "35964327"