QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#590743#833. Cells Blockingxwh_MarvelousWA 676ms411548kbC++142.3kb2024-09-26 10:47:082024-09-26 10:47:08

Judging History

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

  • [2024-09-26 10:47:08]
  • 评测
  • 测评结果:WA
  • 用时:676ms
  • 内存:411548kb
  • [2024-09-26 10:47:08]
  • 提交

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];
	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: 0ms
memory: 13856kb

input:

3 3
...
...
...

output:

17

result:

ok 1 number(s): "17"

Test #2:

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

input:

3 3
.**
.*.
...

output:

15

result:

ok 1 number(s): "15"

Test #3:

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

input:

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

output:

6

result:

ok 1 number(s): "6"

Test #4:

score: 0
Accepted
time: 0ms
memory: 9732kb

input:

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

output:

66

result:

ok 1 number(s): "66"

Test #5:

score: 0
Accepted
time: 0ms
memory: 9616kb

input:

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

output:

1378

result:

ok 1 number(s): "1378"

Test #6:

score: 0
Accepted
time: 615ms
memory: 411124kb

input:

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

output:

17999999

result:

ok 1 number(s): "17999999"

Test #7:

score: 0
Accepted
time: 621ms
memory: 410764kb

input:

3000 3000
...................................................................................................................*......................................................................................................................................................................*..........

output:

17981671

result:

ok 1 number(s): "17981671"

Test #8:

score: 0
Accepted
time: 634ms
memory: 411268kb

input:

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

output:

17963615

result:

ok 1 number(s): "17963615"

Test #9:

score: 0
Accepted
time: 666ms
memory: 408520kb

input:

3000 3000
.........................................................................................................*...........................................................................................................................................................................................

output:

17945165

result:

ok 1 number(s): "17945165"

Test #10:

score: 0
Accepted
time: 668ms
memory: 406524kb

input:

3000 3000
......................................................................................................................................*........................................................................................................................................*.....................

output:

17928211

result:

ok 1 number(s): "17928211"

Test #11:

score: 0
Accepted
time: 653ms
memory: 411548kb

input:

3000 3000
...........................................*.........................................................................................................................................................................................................................................................

output:

17911522

result:

ok 1 number(s): "17911522"

Test #12:

score: 0
Accepted
time: 643ms
memory: 407952kb

input:

3000 3000
..............................*................................................................................................................*.....................................................................................................................................................

output:

17892283

result:

ok 1 number(s): "17892283"

Test #13:

score: 0
Accepted
time: 659ms
memory: 403992kb

input:

3000 3000
................................................................*....*................................................................................................................................................................................*..............................................

output:

17873837

result:

ok 1 number(s): "17873837"

Test #14:

score: 0
Accepted
time: 676ms
memory: 402820kb

input:

3000 3000
............................................................................................*.............................................................................*.....................................................................................................*....................

output:

17856701

result:

ok 1 number(s): "17856701"

Test #15:

score: 0
Accepted
time: 659ms
memory: 404204kb

input:

3000 3000
......................................*..........................................................................................................................................................*...................................................................................................

output:

17837857

result:

ok 1 number(s): "17837857"

Test #16:

score: 0
Accepted
time: 655ms
memory: 400664kb

input:

3000 3000
.................................................................................................................................................................................................................................*...................................................................

output:

17819731

result:

ok 1 number(s): "17819731"

Test #17:

score: 0
Accepted
time: 609ms
memory: 305032kb

input:

3000 3000
......**.....*.......*.*..........*..*...............**.............*.......*......*........*...*.....*.*.................*......*....*.........*....................*.................*.......................*.......*..*.*.......*.......................*..........*..*......................*...

output:

16202000

result:

ok 1 number(s): "16202000"

Test #18:

score: -100
Wrong Answer
time: 451ms
memory: 214308kb

input:

3000 3000
..................*....*....*...*.*.............*.............*....*.*..*...*...*...*....*.................*...*.*.***...*....*......*.......**...*.......*.*...**...*...*...**.........*..........*.....*.*....*..*.......*.........*..*.....*...............**.......*.....*.*..*.*.*........*.....

output:

21600120

result:

wrong answer 1st numbers differ - expected: '21600132', found: '21600120'