QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#590735 | #833. Cells Blocking | xwh_Marvelous | WA | 534ms | 366424kb | C++14 | 2.0kb | 2024-09-26 10:44:26 | 2024-09-26 10:44:26 |
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];
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;
}
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]){
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]=='.');
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: 2ms
memory: 11736kb
input:
3 3 ... ... ...
output:
17
result:
ok 1 number(s): "17"
Test #2:
score: 0
Accepted
time: 0ms
memory: 11752kb
input:
3 3 .** .*. ...
output:
15
result:
ok 1 number(s): "15"
Test #3:
score: 0
Accepted
time: 0ms
memory: 7592kb
input:
3 4 **** .... ****
output:
6
result:
ok 1 number(s): "6"
Test #4:
score: 0
Accepted
time: 0ms
memory: 7604kb
input:
5 5 *.... .*.*. ***** *.*** ..*..
output:
66
result:
ok 1 number(s): "66"
Test #5:
score: 0
Accepted
time: 1ms
memory: 7592kb
input:
10 10 ...***.*.. **...*.*** ...***.*.. .**...*.*. .*****..*. ..*.****.* .**...**** ..*..*.*.* *.*.**.... ....**...*
output:
1378
result:
ok 1 number(s): "1378"
Test #6:
score: 0
Accepted
time: 534ms
memory: 366424kb
input:
3000 3000 .....................................................................................................................................................................................................................................................................................................
output:
17999999
result:
ok 1 number(s): "17999999"
Test #7:
score: -100
Wrong Answer
time: 528ms
memory: 363516kb
input:
3000 3000 ...................................................................................................................*......................................................................................................................................................................*..........
output:
35963345
result:
wrong answer 1st numbers differ - expected: '17981671', found: '35963345'