求助
查看原帖
求助
350558
_wsq_楼主2025/7/3 18:05

我的代码在本地会 RE,甚至即使加上 -Wl,--stack=1073741824 还是会 RE,但是放到洛谷上就能 AC。求助这是为什么。

#include<bits/stdc++.h>
using namespace std;
int h,w,k,l,xh,yh,xv,yv,tx,ty,cnt[1505][1505][5];
string s[1505];
bool vis[1505][1505];
void dfs(int x,int y){
	if(x==tx&&y==ty){
		cout<<"YES";
		exit(0);
	}
	bool d1=false,d2=false,d3=false,d4=false;
	if(y!=1){
		if(s[x][y-2]!='X'&&min(cnt[x][y][3],cnt[x][y-1][3])+min(cnt[x][y][4],cnt[x][y-1][4])-1>=l&&!vis[x][y-1]){
			vis[x][y-1]=d2=true;
		}
	}
	if(y!=w){
		if(s[x][y]!='X'&&min(cnt[x][y][3],cnt[x][y+1][3])+min(cnt[x][y][4],cnt[x][y+1][4])-1>=l&&!vis[x][y+1]){
			vis[x][y+1]=d1=true;
		}
	}
	if(x!=h){
		if(s[x+1][y-1]!='X'&&min(cnt[x][y][1],cnt[x+1][y][1])+min(cnt[x][y][2],cnt[x+1][y][2])-1>=k&&!vis[x+1][y]){
			vis[x+1][y]=d3=true;
		}
	}
	if(x!=1){
		if(s[x-1][y-1]!='X'&&min(cnt[x][y][1],cnt[x-1][y][1])+min(cnt[x][y][2],cnt[x-1][y][2])-1>=k&&!vis[x-1][y]){
			vis[x-1][y]=d4=true;
		}
	}
	if(d1){
		dfs(x,y+1);
	}
	if(d2){
		dfs(x,y-1);
	}
	if(d3){
		dfs(x+1,y);
	}
	if(d4){
		dfs(x-1,y);
	}
	return;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>w>>h>>k>>l>>yh>>xh>>yv>>xv;
	xh++;
	yh++;
	xv++;
	yv++;
	for(int i=1;i<=h;i++){
		cin>>s[i];
		for(int j=1;j<=w;j++){
			if(s[i][j-1]=='*'){
				tx=i;
				ty=j;
			}
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cnt[i][j][1]=(s[i][j-1]=='X'?0:cnt[i][j-1][1]+1);
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=w;j;j--){
			cnt[i][j][2]=(s[i][j-1]=='X'?0:cnt[i][j+1][2]+1);
		}
	}
	for(int i=1;i<=w;i++){
		for(int j=1;j<=h;j++){
			cnt[j][i][3]=(s[j][i-1]=='X'?0:cnt[j-1][i][3]+1);
		}
	}
	for(int i=1;i<=w;i++){
		for(int j=h;j;j--){
			cnt[j][i][4]=(s[j][i-1]=='X'?0:cnt[j+1][i][4]+1);
		}
	}
	vis[xh][yv]=true;
	dfs(xh,yv);
	cout<<"NO";
	return 0;
}
2025/7/3 18:05
加载中...