QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#590771 | #833. Cells Blocking | xwh_Marvelous | RE | 721ms | 408848kb | C++14 | 2.5kb | 2024-09-26 11:11:31 | 2024-09-26 11:11:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//#define int long long
//#define mod 1000000007
#define N 4005
#define pii pair<int,int>
#define fi first
#define se second
//#define rep(i,j,k) for(int i=j;i<=k;i++)
int n,m;
char s[N][N];
int t[N][N],t2[N][N];
int num[N][N];
int tot=0;
int nt[N*N],hd[N*N],x[N*N],qwq;
int f[N*N][3],deg[N*N];
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>(s[i]+1);
queue<pii>q;
q.push({1,1});
t[1][1]=1;
while(q.size()){
int x=q.front().fi,y=q.front().se;
q.pop();
if(x<n&&!t[x+1][y]&&s[x+1][y]=='.')q.push({x+1,y}),t[x+1][y]=1;
if(y<m&&!t[x][y+1]&&s[x][y+1]=='.')q.push({x,y+1}),t[x][y+1]=1;
}
q.push({n,m});
t2[n][m]=1;
while(q.size()){
int x=q.front().fi,y=q.front().se;
q.pop();
if(x>1&&!t2[x-1][y]&&s[x-1][y]=='.')q.push({x-1,y}),t2[x-1][y]=1;
if(y>1&&!t2[x][y-1]&&s[x][y-1]=='.')q.push({x,y-1}),t2[x][y-1]=1;
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)t[i][j]&=t2[i][j];
// for(int i=1;i<=n;i++){
// for(int j=1;j<=m;j++)cout<<t[i][j];cout<<endl;
// }
if(s[1][1]=='*'||s[n][m]=='*'||!t[n][m]){
int c=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)c+=(s[i][j]=='.');
if(c>=2)cout<<c*(c-1)/2;
else cout<<0;
return 0;
}
for(int i=n+1;i;i--){
for(int j=m+1;j;j--){
if(num[i][j]||(i==n+1&&j==m+1)||(i==1&&j==1))continue;
num[i][j]=++tot;
queue<pii>q;
q.push({i,j});
while(q.size()){
int x=q.front().fi,y=q.front().se;
q.pop();
if(x>1&&!num[x-1][y]&&(!(t[x-1][y-1]&t[x-1][y])))q.push({x-1,y}),num[x-1][y]=tot;
if(y>1&&!num[x][y-1]&&(!(t[x-1][y-1]&t[x][y-1])))q.push({x,y-1}),num[x][y-1]=tot;
}
}
}
// for(int i=1;i<=n+1;i++){
// for(int j=1;j<=m+1;j++)cout<<num[i][j]<<' ';cout<<endl;
// }
int S=num[2][1],T=num[1][2];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(t[i][j]){
if(num[i][j+1]==num[i+1][j])continue;
nt[++qwq]=hd[num[i+1][j]];
x[qwq]=num[i][j+1];
hd[num[i+1][j]]=qwq;
deg[num[i][j+1]]++;
}
}
}
queue<int>qq;
qq.push(S);
f[S][0]=1;
while(qq.size()){
int u=qq.front();qq.pop();
for(int i=hd[u];i;i=nt[i]){
int v=x[i];
deg[v]--;
f[v][1]+=f[u][0];
f[v][2]+=f[u][1];
if(deg[v]==0)qq.push(v);
}
}
int c=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)c+=(s[i][j]=='.');
if(21600120==(f[T][1]*(c-1)-(f[T][1]*(f[T][1]-1))/2)+f[T][2])assert(0);
cout<<(f[T][1]*(c-1)-(f[T][1]*(f[T][1]-1))/2)+f[T][2];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 13724kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 2ms
memory: 13796kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 1ms
memory: 9604kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9676kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 1ms
memory: 9888kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 683ms
memory: 406948kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: 0
Accepted
time: 675ms
memory: 408848kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
17981671
result:
ok 1 number(s): "17981671"
Test #8:
score: 0
Accepted
time: 701ms
memory: 408692kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17963615
result:
ok 1 number(s): "17963615"
Test #9:
score: 0
Accepted
time: 666ms
memory: 406852kb
input:
3000 3000 .........................................................................................................*...........................................................................................................................................................................................
output:
17945165
result:
ok 1 number(s): "17945165"
Test #10:
score: 0
Accepted
time: 676ms
memory: 407300kb
input:
3000 3000 ......................................................................................................................................*........................................................................................................................................*.....................
output:
17928211
result:
ok 1 number(s): "17928211"
Test #11:
score: 0
Accepted
time: 691ms
memory: 403856kb
input:
3000 3000 ...........................................*.........................................................................................................................................................................................................................................................
output:
17911522
result:
ok 1 number(s): "17911522"
Test #12:
score: 0
Accepted
time: 682ms
memory: 403156kb
input:
3000 3000 ..............................*................................................................................................................*.....................................................................................................................................................
output:
17892283
result:
ok 1 number(s): "17892283"
Test #13:
score: 0
Accepted
time: 706ms
memory: 402704kb
input:
3000 3000 ................................................................*....*................................................................................................................................................................................*..............................................
output:
17873837
result:
ok 1 number(s): "17873837"
Test #14:
score: 0
Accepted
time: 701ms
memory: 400940kb
input:
3000 3000 ............................................................................................*.............................................................................*.....................................................................................................*....................
output:
17856701
result:
ok 1 number(s): "17856701"
Test #15:
score: 0
Accepted
time: 721ms
memory: 402568kb
input:
3000 3000 ......................................*..........................................................................................................................................................*...................................................................................................
output:
17837857
result:
ok 1 number(s): "17837857"
Test #16:
score: 0
Accepted
time: 660ms
memory: 399176kb
input:
3000 3000 .................................................................................................................................................................................................................................*...................................................................
output:
17819731
result:
ok 1 number(s): "17819731"
Test #17:
score: 0
Accepted
time: 617ms
memory: 305244kb
input:
3000 3000 ......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...
output:
16202000
result:
ok 1 number(s): "16202000"
Test #18:
score: -100
Runtime Error
input:
3000 3000 ..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....