70分蒟蒻 TLE求调(玄关)
  • 板块P1141 01迷宫
  • 楼主CHENGUOTAO
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/1 13:52
  • 上次更新2024/11/1 17:47:44
查看原帖
70分蒟蒻 TLE求调(玄关)
971284
CHENGUOTAO楼主2024/11/1 13:52
#include<bits/stdc++.h>
using namespace std;
long long n,T,x,y,ans;
string s;
long long cx[10]={0,0,-1,1};
long long cy[10]={1,-1,0,0};
char a[1005][1005];
bool vis[1005][1005];
void dfs(int _x,int _y){
	vis[_x][_y]=1;
	ans++;
	for(int i=0;i<4;i++){
		int xx=_x+cx[i];
		int yy=_y+cy[i];
		if(xx>0&&xx<=n&&yy>0&&yy<=n
		&&vis[xx][yy]==0){
			if(a[_x][_y]=='1')
				if(a[xx][yy]=='0')
					dfs(xx,yy);
			if(a[_x][_y]=='0')
				if(a[xx][yy]=='1')
					dfs(xx,yy);
		}
	}
	return ;
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%lld%lld",&n,&T);
	for(int i=1;i<=n;i++){
		cin>>s;
		for(int j=1;j<=n;j++){
			a[i][j]=s[j-1];
		}
	}
	while(T--){
		scanf("%lld%lld",&x,&y);
		ans=0;
		dfs(x,y);
		memset(vis,false,sizeof(vis));
		printf("%lld\n",ans);
	}
	return 0;
}
2024/11/1 13:52
加载中...