求调
查看原帖
求调
1218651
__harry_potter__楼主2024/8/21 14:42

WA的数据点

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 403
int ans,s[N][N],b[N][N],g[N][N],n,m,i,j,k;
int dx[7]={0,-1,0,1,0};
int dy[7]={0,0,1,0,-1};
char c;
struct ll{
	int x,y;
	int bx,by;
}p,ne;
queue<ll> q;
int bfs(){
	p.x=p.y=2;
	p.bx=1;p.by=0;
	q.push(p);
	p.bx=0;p.by=1;
	q.push(p);
	while(q.size()){
		p=q.front();
		q.pop();
		while(!b[p.x+p.bx][p.y+p.by]){
			ans+=(1-s[p.x][p.y]);
			s[p.x][p.y]=1;
			g[p.x][p.y]++;
			p.x+=p.bx;
			p.y+=p.by;
		}
		ans+=(1-s[p.x][p.y]);
		s[p.x][p.y]=1;	
		g[p.x][p.y]++;
		for(i=1;i<=4;i++){
			ne.x=p.x+dx[i];
			ne.y=p.y+dy[i];
			ne.bx=dx[i];
			ne.by=dy[i];
			if(ne.x<=n&&ne.x>=1&&ne.y<=m&&ne.y>=1){
				if(g[ne.x][ne.y]<4&&!b[ne.x][ne.y]){
					q.push(ne);
				}
			}
		}
	}
	return ans;
}
signed main()
{
	cin>>n>>m;
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			cin>>c;
			b[i][j]=(c=='#');
		}
	}
	cout<<bfs();
}
2024/8/21 14:42
加载中...