QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#331484 | #833. Cells Blocking | CharlieVinnie | AC ✓ | 266ms | 154856kb | C++17 | 2.4kb | 2024-02-18 11:50:48 | 2024-02-18 11:51:11 |
Judging History
answer
#include "bits/stdc++.h"
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](auto...){}(__VA_ARGS__)
#define debuga(...) [](auto...){}(__VA_ARGS__)
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
using namespace std; typedef long long ll;
constexpr int N=3e3+5;
char mp[N][N]; int n,m,U[N][N],V[N][N],f[N][N],g[N][N]; bool S[N][N],T[N][N];
signed main(){
atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
cin>>n>>m; For(i,1,n) cin>>(mp[i]+1);
int tt=0; For(i,1,n) For(j,1,m) tt+=(mp[i][j]=='.');
For(i,1,n) For(j,1,m) if(mp[i][j]=='.') {
if(i==1&&j==1) { S[i][j]=1; continue; }
if(S[i-1][j]) S[i][j]=1;
if(S[i][j-1]) S[i][j]=1;
}
if(!S[n][m]) return cout<<1ll*tt*(tt-1)/2<<'\n',0;
int u=n,v=m; V[n][m]=1;
while(u!=1||v!=1){
if(S[u-1][v]) u--; else v--;
V[u][v]=1;
}
For(i,1,n) For(j,1,m) S[i][j]=0;
For(i,1,n) For(j,1,m) if(mp[i][j]=='.') {
if(i==1&&j==1) { S[i][j]=1; continue; }
if(S[i][j-1]) S[i][j]=1;
if(S[i-1][j]) S[i][j]=1;
}
Rev(i,n,1) Rev(j,m,1) if(mp[i][j]=='.') {
if(i==n&&j==m) { T[i][j]=1; continue; }
if(T[i+1][j]) T[i][j]=1;
if(T[i][j+1]) T[i][j]=1;
}
u=n,v=m; U[n][m]=1;
while(u!=1||v!=1){
debug(u,v);
if(S[u][v-1]) v--; else u--;
U[u][v]=1;
}
ll ans=0; For(i,1,n) For(j,1,m) if(U[i][j]&&V[i][j]) tt--,ans+=tt;
debug(ans);
For(i,1,n) For(j,1,m) if(S[i][j]) {
if(i==1&&j==1) continue;
if(S[i][j-1]) f[i][j]=f[i][j-1]; else f[i][j]=f[i-1][j];
f[i][j]+=(V[i][j]&&!U[i][j]);
}
Rev(i,n,1) Rev(j,m,1) if(T[i][j]) {
if(i==n&&j==m) continue;
if(T[i+1][j]) g[i][j]=g[i+1][j]; else g[i][j]=g[i][j+1];
g[i][j]+=(V[i][j]&&!U[i][j]);
}
For(i,1,n) For(j,1,m) if(U[i][j]&&!V[i][j]){
u=i,v=j; do u--,v++; while(u>=1&&v<=m&&(!S[u][v]||!T[u][v]));
ll res=f[u][v]+g[u][v]-(V[u][v]&&!U[u][v]); ans+=res;
debug(i,j,u,v,res);
}
cout<<ans<<'\n';
return 0;
}
// CONTINUE, NON-STOPPING, FOR CHARLIEY
// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// Started Coding On: February 18 Sun, 11 : 00 : 04
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 11852kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 2ms
memory: 11888kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5660kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5620kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 0ms
memory: 7892kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 162ms
memory: 150832kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 193ms
memory: 149484kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 172ms
memory: 149608kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 184ms
memory: 152348kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 157ms
memory: 153544kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: 0
Accepted
time: 152ms
memory: 149440kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911522
result:
ok 1 number(s): "17911522"
Test #12:
score: 0
Accepted
time: 172ms
memory: 150796kb
input:
3000 3000 ..............................*................................................................................................................*.....................................................................................................................................................
output:
17892283
result:
ok 1 number(s): "17892283"
Test #13:
score: 0
Accepted
time: 150ms
memory: 154856kb
input:
3000 3000 ................................................................*....*................................................................................................................................................................................*..............................................
output:
17873837
result:
ok 1 number(s): "17873837"
Test #14:
score: 0
Accepted
time: 172ms
memory: 149420kb
input:
3000 3000 ............................................................................................*.............................................................................*.....................................................................................................*....................
output:
17856701
result:
ok 1 number(s): "17856701"
Test #15:
score: 0
Accepted
time: 180ms
memory: 150820kb
input:
3000 3000 ......................................*..........................................................................................................................................................*...................................................................................................
output:
17837857
result:
ok 1 number(s): "17837857"
Test #16:
score: 0
Accepted
time: 196ms
memory: 149512kb
input:
3000 3000 .................................................................................................................................................................................................................................*...................................................................
output:
17819731
result:
ok 1 number(s): "17819731"
Test #17:
score: 0
Accepted
time: 229ms
memory: 151680kb
input:
3000 3000 ......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...
output:
16202000
result:
ok 1 number(s): "16202000"
Test #18:
score: 0
Accepted
time: 266ms
memory: 147672kb
input:
3000 3000 ..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....
output:
21600132
result:
ok 1 number(s): "21600132"
Test #19:
score: 0
Accepted
time: 119ms
memory: 16400kb
input:
3000 3000 ..*.**...*...............*........*.*..*.*.....*........*.*..........***..*..*..*..*.*....*...*.*.....***.*...*........*..*.****..*.*....**.......*......*....*..*......*......*..*..*.*..*....*..**.*.......**.*...*....**.....**..*......*...*....*..*.**.*..***...*.....*....***.*........*.......
output:
19862779430431
result:
ok 1 number(s): "19862779430431"
Test #20:
score: 0
Accepted
time: 123ms
memory: 16536kb
input:
3000 3000 .**.**..***....*.*....*..*...*.**.**.**.......*...*........*.**.*...*...**..*...*.*.**.*.*.*.*..*...*.....*.*.**.*.*....*.**.....*..**.**.*....**.**.**..*..**...*...***.**.*.*......**.**.*...****.....***.*..*.**.*......*..**.**.**.....**...*.*..***.******...**....****..***..**.*........*.....
output:
14601805246666
result:
ok 1 number(s): "14601805246666"
Test #21:
score: 0
Accepted
time: 1ms
memory: 5736kb
input:
1 1 *
output:
0
result:
ok 1 number(s): "0"
Test #22:
score: 0
Accepted
time: 0ms
memory: 11876kb
input:
1 1 .
output:
0
result:
ok 1 number(s): "0"
Test #23:
score: 0
Accepted
time: 0ms
memory: 12032kb
input:
2 2 .. ..
output:
6
result:
ok 1 number(s): "6"
Test #24:
score: 0
Accepted
time: 124ms
memory: 15568kb
input:
3000 3000 .***..**..*.*.*..*...**.*.**...***.....*..***.***.***.*..***.*......*.**.***.***.*...**.*.*..***.*..*.**..***.....*.*...***.*.***.*...*.*.....***.*..**...*.*..*.******.*.*...**.*..**.**.**.*.**..***.**.***..*......**.***.**.*....*..*.....*...*..*.*..*..*.*...**.**...*..**..***.**..*....*.....
output:
10151159625145
result:
ok 1 number(s): "10151159625145"
Test #25:
score: 0
Accepted
time: 92ms
memory: 13612kb
input:
3000 3000 *******************************************************************************************************************************************************************************************************************************************************.******************************************...
output:
39716328
result:
ok 1 number(s): "39716328"
Test #26:
score: 0
Accepted
time: 150ms
memory: 152256kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
35988321
result:
ok 1 number(s): "35988321"
Test #27:
score: 0
Accepted
time: 182ms
memory: 148284kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35981866
result:
ok 1 number(s): "35981866"
Test #28:
score: 0
Accepted
time: 171ms
memory: 152316kb
input:
3000 3000 ...**................................................................................................................................................................................................................................................................................................
output:
17988153
result:
ok 1 number(s): "17988153"
Test #29:
score: 0
Accepted
time: 163ms
memory: 150876kb
input:
3000 3000 ...*.*...............................................................................................................................................................................................................................................................................................
output:
35969654
result:
ok 1 number(s): "35969654"
Test #30:
score: 0
Accepted
time: 159ms
memory: 149444kb
input:
3000 3000 ..*..................................................................................................................................................................................................................................................................................................
output:
17982216
result:
ok 1 number(s): "17982216"
Test #31:
score: 0
Accepted
time: 159ms
memory: 149504kb
input:
3000 3000 ....**.*.............................................................................................................................................................................................................................................................................................
output:
71916090
result:
ok 1 number(s): "71916090"
Test #32:
score: 0
Accepted
time: 181ms
memory: 153556kb
input:
3000 3000 ....****.............................................................................................................................................................................................................................................................................................
output:
71903186
result:
ok 1 number(s): "71903186"
Test #33:
score: 0
Accepted
time: 178ms
memory: 149520kb
input:
3000 3000 .........*...........................................................................................................................................................................................................................................................................................
output:
17973051
result:
ok 1 number(s): "17973051"
Test #34:
score: 0
Accepted
time: 176ms
memory: 149392kb
input:
3000 3000 .*.......*.............................................................................................................*................................................................................*............................................................................................
output:
35630636
result:
ok 1 number(s): "35630636"
Test #35:
score: 0
Accepted
time: 159ms
memory: 149444kb
input:
3000 3000 .**...........................*..........................................................................................................................................*...........................................................................................................................
output:
44529907
result:
ok 1 number(s): "44529907"
Test #36:
score: 0
Accepted
time: 182ms
memory: 150860kb
input:
3000 3000 ....*................................................................................................................................................................................................................................................................................................
output:
53426863
result:
ok 1 number(s): "53426863"
Test #37:
score: 0
Accepted
time: 151ms
memory: 153472kb
input:
3000 3000 ..*.*........................................................................*............................*...............*.............................................................................................................................................*........*...................
output:
53419301
result:
ok 1 number(s): "53419301"
Test #38:
score: 0
Accepted
time: 185ms
memory: 150812kb
input:
3000 3000 ......*.........*...................................................................................*.....................................................................................................................*................................................*.........................
output:
26705269
result:
ok 1 number(s): "26705269"
Test #39:
score: 0
Accepted
time: 187ms
memory: 152088kb
input:
3000 3000 ....*.**....*................*............................*..........*...............................................................................................................................................................................................................................
output:
17799069
result:
ok 1 number(s): "17799069"
Test #40:
score: 0
Accepted
time: 170ms
memory: 153540kb
input:
3000 3000 ...***.......................................*...........*.....................*........*...........................................................................................................................................................*................................................
output:
53393629
result:
ok 1 number(s): "53393629"
Test #41:
score: 0
Accepted
time: 186ms
memory: 153588kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
98852811
result:
ok 1 number(s): "98852811"
Test #42:
score: 0
Accepted
time: 0ms
memory: 12048kb
input:
1 3000 ........................................................................................................................................................................................................................................................................................................
output:
4498500
result:
ok 1 number(s): "4498500"
Test #43:
score: 0
Accepted
time: 189ms
memory: 150912kb
input:
3000 3000 .*.....*...........................................................................................................*...................................*........................................................................................*............*.......................................
output:
88979547
result:
ok 1 number(s): "88979547"
Test #44:
score: 0
Accepted
time: 169ms
memory: 149576kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
35964327
result:
ok 1 number(s): "35964327"