QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#732293 | #833. Cells Blocking | TheZone | AC ✓ | 154ms | 155856kb | C++14 | 4.8kb | 2024-11-10 13:55:46 | 2024-11-10 13:55:47 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define F(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define G(i,l,r) for(int i=(l),i##end=(r);i>=i##end;--i)
#define x first
#define y second
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define ep emplace_back
using namespace std;
const int N=3009;
char s[N][N];
int _1[N][N],_2[N][N];
int dd[N][N],dr[N][N],rr[N][N],rd[N][N];
int rrsum[2*N];
int drsum[2*N];
int rdsum[2*N];
int ddsum[2*N];
ll ans,num;
int cnt[2*N];
int n,m;
pii kkr[2*N],kkd[2*N];
void solve()
{
int x=1,y=1;
kkr[2]=kkd[2]=mp(1,1);
while(x!=n||y!=m)
{
if(x<n && s[x+1][y]=='.') ++x;
else ++y;
kkd[x+y]=mp(x,y);
}
x=y=1;
while(x!=n||y!=m)
{
if(y<m && s[x][y+1]=='.') ++y;
else ++x;
kkr[x+y]=mp(x,y);
}
}
void chkmax(int &a,int b)
{
if(b>a) a=b;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>m;
F(i,1,n)cin>>s[i]+1;
_1[1][1]=s[1][1]=='.';F(i,1,n)F(j,1,m) if(s[i][j]=='.') _1[i][j]|=_1[i][j-1]|_1[i-1][j];
_2[n][m]=s[n][m]=='.';G(i,n,1)G(j,m,1) if(s[i][j]=='.') _2[i][j]|=_2[i][j+1]|_2[i+1][j];
F(i,1,n)F(j,1,m)if(s[i][j]=='.'&&!(_1[i][j]&&_2[i][j]))s[i][j]='^';
F(i,1,n)F(j,1,m)cnt[i+j]+=s[i][j]=='.',num+=s[i][j]!='*';
if(s[1][1]!='.')
{
cout<<num*(num-1)/2<<'\n';
return 0;
}
F(i,2,n+m) if(cnt[i]==1) ans+=--num;
solve();
G(i,n,1)G(j,m,1)
{
if(s[i][j]!='.') continue;
if(kkd[i+j+1]==mp(i,j+1)) dd[i][j]=i+j+1;
else if(kkr[i+j+1]!=mp(i,j+1))chkmax(dd[i][j],dd[i][j+1]);
if(kkd[i+1+j]==mp(i+1,j)) chkmax(dd[i][j],i+j+1);
else if(kkr[i+j+1]!=mp(i+1,j))chkmax(dd[i][j],dd[i+1][j]);
}
G(i,n,1)G(j,m,1)
{
if(s[i][j]!='.') continue;
if(kkr[i+j+1]==mp(i,j+1)) rr[i][j]=i+j+1;
else if(kkd[i+j+1]!=mp(i,j+1))chkmax(rr[i][j],rr[i][j+1]);
if(kkr[i+1+j]==mp(i+1,j)) chkmax(rr[i][j],i+j+1);
else if(kkd[i+j+1]!=mp(i+1,j))chkmax(rr[i][j],rr[i+1][j]);
}
F(i,1,n+m) ddsum[i]=max(ddsum[i-1],dd[kkd[i].x][kkd[i].y]);
F(i,1,n+m) rrsum[i]=max(rrsum[i-1],rr[kkr[i].x][kkr[i].y]);
F(i,1,n+m) rdsum[i]=max(rdsum[i-1],dd[kkr[i].x][kkr[i].y]);
F(i,1,n+m) drsum[i]=max(drsum[i-1],rr[kkd[i].x][kkd[i].y]);
F(i,2,n+m)
F(j,2,n+m)
{
if(cnt[i]==1 || cnt[j]==1) continue;
// cout<<i<<"-"<<j<<":"<<rdsum[i-1]<<" "<<rrsum[i-1]<<" "<<ddsum[j-1]<<" "<<drsum[j-1]<<'\n';
if(max(rdsum[i-1],ddsum[j-1])>j || max(drsum[j-1],rrsum[i-1])>i) continue;
ans++;
}
cout<<ans<<'\n';
}
/*#include<bits/stdc++.h>
#define ll long long
#define F(i,l,r) for(int i=(l),i##end=(r);i<=i##end;++i)
#define G(i,l,r) for(int i=(l),i##end=(r);i>=i##end;--i)
#define x first
#define y second
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define ep emplace_back
using namespace std;
const int N=3009;
char s[N][N];
int _1[N][N],_2[N][N];
int dd[N][N],dr[N][N],rr[N][N],rd[N][N];
int rrsum[2*N];
int drsum[2*N];
int rdsum[2*N];
int ddsum[2*N];
ll ans,num;
int cnt[2*N];
int n,m;
pii kkr[2*N],kkd[2*N];
void solve()
{
int x=1,y=1;
kkr[2]=kkd[2]=mp(1,1);
while(x!=n||y!=m)
{
if(x<n && s[x+1][y]=='.') ++x;
else ++y;
kkd[x+y]=mp(x,y);
}
x=y=1;
while(x!=n||y!=m)
{
if(y<m && s[x][y+1]=='.') ++y;
else ++x;
kkr[x+y]=mp(x,y);
}
}
void chkmax(int &a,int b)
{
if(b>a) a=b;
}
int main()
{
ios::sync_with_stdio(false);cin.tie(0);
cin>>n>>m;
F(i,1,n)cin>>s[i]+1;
_1[1][1]=s[1][1]=='.';F(i,1,n)F(j,1,m) if(s[i][j]=='.') _1[i][j]|=_1[i][j-1]|_1[i-1][j];
_2[n][m]=s[n][m]=='.';G(i,n,1)G(j,m,1) if(s[i][j]=='.') _2[i][j]|=_2[i][j+1]|_2[i+1][j];
F(i,1,n)F(j,1,m)if(s[i][j]=='.'&&!(_1[i][j]&&_2[i][j]))s[i][j]='^';
F(i,1,n)F(j,1,m)cnt[i+j]+=s[i][j]=='.',num+=s[i][j]!='*';
if(s[1][1]!='.')
{
cout<<num*(num-1)/2<<'\n';
return 0;
}
F(i,2,n+m) if(cnt[i]==1) ans+=--num;
solve();
G(i,n,1)G(j,m,1)
{
if(s[i][j]!='.') continue;
if(kkd[i+j+1]==mp(i,j+1)) dd[i][j]=i+j+1;
else if(kkr[i+j+1]!=mp(i,j+1))chkmax(dd[i][j],dd[i][j+1]);
if(kkd[i+1+j]==mp(i+1,j)) chkmax(dd[i][j],i+j+1);
else if(kkr[i+j+1]!=mp(i+1,j))chkmax(dd[i][j],dd[i+1][j]);
}
G(i,n,1)G(j,m,1)
{
if(s[i][j]!='.') continue;
if(kkr[i+j+1]==mp(i,j+1)) rr[i][j]=i+j+1;
else if(kkd[i+j+1]!=mp(i,j+1))chkmax(rr[i][j],rr[i][j+1]);
if(kkr[i+1+j]==mp(i+1,j)) chkmax(rr[i][j],i+j+1);
else if(kkd[i+j+1]!=mp(i+1,j))chkmax(rr[i][j],rr[i+1][j]);
}
F(i,1,n+m) ddsum[i]=max(ddsum[i-1],dd[kkd[i].x][kkd[i].y]);
F(i,1,n+m) rrsum[i]=max(rrsum[i-1],rr[kkr[i].x][kkr[i].y]);
F(i,1,n+m) rdsum[i]=max(rdsum[i-1],dd[kkr[i].x][kkr[i].y]);
F(i,1,n+m) drsum[i]=max(drsum[i-1],rr[kkd[i].x][kkd[i].y]);
F(i,2,n+m)
F(j,2,n+m)
{
if(cnt[i]==1 || cnt[j]==1) continue;
// cout<<i<<"-"<<j<<":"<<rdsum[i-1]<<" "<<rrsum[i-1]<<" "<<ddsum[j-1]<<" "<<drsum[j-1]<<'\n';
if(max(rdsum[i-1],ddsum[j-1])>j || max(drsum[j-1],rrsum[i-1])>i) continue;
ans++;
}
cout<<ans<<'\n';
}*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 9864kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9772kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 0ms
memory: 9744kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9724kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 1ms
memory: 9672kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 136ms
memory: 153872kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 136ms
memory: 153832kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 119ms
memory: 153804kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 120ms
memory: 153780kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 128ms
memory: 153820kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: 0
Accepted
time: 112ms
memory: 153752kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911522
result:
ok 1 number(s): "17911522"
Test #12:
score: 0
Accepted
time: 131ms
memory: 153664kb
input:
3000 3000 ..............................*................................................................................................................*.....................................................................................................................................................
output:
17892283
result:
ok 1 number(s): "17892283"
Test #13:
score: 0
Accepted
time: 138ms
memory: 153680kb
input:
3000 3000 ................................................................*....*................................................................................................................................................................................*..............................................
output:
17873837
result:
ok 1 number(s): "17873837"
Test #14:
score: 0
Accepted
time: 112ms
memory: 155580kb
input:
3000 3000 ............................................................................................*.............................................................................*.....................................................................................................*....................
output:
17856701
result:
ok 1 number(s): "17856701"
Test #15:
score: 0
Accepted
time: 128ms
memory: 153576kb
input:
3000 3000 ......................................*..........................................................................................................................................................*...................................................................................................
output:
17837857
result:
ok 1 number(s): "17837857"
Test #16:
score: 0
Accepted
time: 120ms
memory: 153496kb
input:
3000 3000 .................................................................................................................................................................................................................................*...................................................................
output:
17819731
result:
ok 1 number(s): "17819731"
Test #17:
score: 0
Accepted
time: 128ms
memory: 149936kb
input:
3000 3000 ......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...
output:
16202000
result:
ok 1 number(s): "16202000"
Test #18:
score: 0
Accepted
time: 154ms
memory: 141288kb
input:
3000 3000 ..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....
output:
21600132
result:
ok 1 number(s): "21600132"
Test #19:
score: 0
Accepted
time: 89ms
memory: 83116kb
input:
3000 3000 ..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......
output:
19862779430431
result:
ok 1 number(s): "19862779430431"
Test #20:
score: 0
Accepted
time: 136ms
memory: 83192kb
input:
3000 3000 .**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....
output:
14601805246666
result:
ok 1 number(s): "14601805246666"
Test #21:
score: 0
Accepted
time: 0ms
memory: 9732kb
input:
1 1 *
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 0ms
memory: 9748kb
input:
1 1 .
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 0ms
memory: 9852kb
input:
2 2 .. ..
output:
6
result:
ok 1 number(s): "6"
Test #24:
score: 0
Accepted
time: 113ms
memory: 83172kb
input:
3000 3000 .***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....
output:
10151159625145
result:
ok 1 number(s): "10151159625145"
Test #25:
score: 0
Accepted
time: 35ms
memory: 58788kb
input:
3000 3000 *******************************************************************************************************************************************************************************************************************************************************.******************************************...
output:
39716328
result:
ok 1 number(s): "39716328"
Test #26:
score: 0
Accepted
time: 128ms
memory: 153844kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
35988321
result:
ok 1 number(s): "35988321"
Test #27:
score: 0
Accepted
time: 130ms
memory: 153880kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35981866
result:
ok 1 number(s): "35981866"
Test #28:
score: 0
Accepted
time: 130ms
memory: 155856kb
input:
3000 3000 ...**................................................................................................................................................................................................................................................................................................
output:
17988153
result:
ok 1 number(s): "17988153"
Test #29:
score: 0
Accepted
time: 119ms
memory: 153764kb
input:
3000 3000 ...*.*...............................................................................................................................................................................................................................................................................................
output:
35969654
result:
ok 1 number(s): "35969654"
Test #30:
score: 0
Accepted
time: 142ms
memory: 153724kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
17982216
result:
ok 1 number(s): "17982216"
Test #31:
score: 0
Accepted
time: 124ms
memory: 153768kb
input:
3000 3000 ....**.*.............................................................................................................................................................................................................................................................................................
output:
71916090
result:
ok 1 number(s): "71916090"
Test #32:
score: 0
Accepted
time: 122ms
memory: 153784kb
input:
3000 3000 ....****.............................................................................................................................................................................................................................................................................................
output:
71903186
result:
ok 1 number(s): "71903186"
Test #33:
score: 0
Accepted
time: 116ms
memory: 153804kb
input:
3000 3000 .........*...........................................................................................................................................................................................................................................................................................
output:
17973051
result:
ok 1 number(s): "17973051"
Test #34:
score: 0
Accepted
time: 127ms
memory: 153648kb
input:
3000 3000 .*.......*.............................................................................................................*................................................................................*............................................................................................
output:
35630636
result:
ok 1 number(s): "35630636"
Test #35:
score: 0
Accepted
time: 144ms
memory: 155512kb
input:
3000 3000 .**...........................*..........................................................................................................................................*...........................................................................................................................
output:
44529907
result:
ok 1 number(s): "44529907"
Test #36:
score: 0
Accepted
time: 138ms
memory: 153760kb
input:
3000 3000 ....*................................................................................................................................................................................................................................................................................................
output:
53426863
result:
ok 1 number(s): "53426863"
Test #37:
score: 0
Accepted
time: 129ms
memory: 153700kb
input:
3000 3000 ..*.*........................................................................*............................*...............*.............................................................................................................................................*........*...................
output:
53419301
result:
ok 1 number(s): "53419301"
Test #38:
score: 0
Accepted
time: 123ms
memory: 153640kb
input:
3000 3000 ......*.........*...................................................................................*.....................................................................................................................*................................................*.........................
output:
26705269
result:
ok 1 number(s): "26705269"
Test #39:
score: 0
Accepted
time: 124ms
memory: 153540kb
input:
3000 3000 ....*.**....*................*............................*..........*...............................................................................................................................................................................................................................
output:
17799069
result:
ok 1 number(s): "17799069"
Test #40:
score: 0
Accepted
time: 130ms
memory: 155524kb
input:
3000 3000 ...***.......................................*...........*.....................*........*...........................................................................................................................................................*................................................
output:
53393629
result:
ok 1 number(s): "53393629"
Test #41:
score: 0
Accepted
time: 125ms
memory: 153816kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
98852811
result:
ok 1 number(s): "98852811"
Test #42:
score: 0
Accepted
time: 6ms
memory: 9976kb
input:
1 3000 ........................................................................................................................................................................................................................................................................................................
output:
4498500
result:
ok 1 number(s): "4498500"
Test #43:
score: 0
Accepted
time: 133ms
memory: 153736kb
input:
3000 3000 .*.....*...........................................................................................................*...................................*........................................................................................*............*.......................................
output:
88979547
result:
ok 1 number(s): "88979547"
Test #44:
score: 0
Accepted
time: 113ms
memory: 153860kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35964327
result:
ok 1 number(s): "35964327"