QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#590731#833. Cells Blockingxwh_MarvelousRE 2ms11808kbC++142.0kb2024-09-26 10:39:372024-09-26 10:39:39

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 10:39:39]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:11808kb
  • [2024-09-26 10:39:37]
  • 提交

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;
vector<int>mp[N];
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]){
				mp[num[i+1][j]].push_back(num[i][j+1]);
				// cout<<num[i+1][j]<<' '<<num[i][j+1]<<endl;
				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 v:mp[u]){
			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: 11788kb

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

score: 0
Accepted
time: 2ms
memory: 11808kb

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

score: 0
Accepted
time: 1ms
memory: 9628kb

input:

3 4
****
....
****

output:

6

result:

ok 1 number(s): "6"

Test #4:

score: 0
Accepted
time: 1ms
memory: 9964kb

input:

5 5
*....
.*.*.
*****
*.***
..*..

output:

66

result:

ok 1 number(s): "66"

Test #5:

score: 0
Accepted
time: 1ms
memory: 9928kb

input:

10 10
...***.*..
**...*.***
...***.*..
.**...*.*.
.*****..*.
..*.****.*
.**...****
..*..*.*.*
*.*.**....
....**...*

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: -100
Runtime Error

input:

3000 3000
.....................................................................................................................................................................................................................................................................................................

output:


result: