#5-#14 WA求调
查看原帖
#5-#14 WA求调
889498
Bei_Gua_楼主2024/7/12 20:02

感觉自己写的没啥问题,还是wa了

求调plz:)

Code:

#include<bits/stdc++.h>
#define int long long
#define inf 5000005
using namespace std;
const int N=3e3+5,U=N-5;
struct Node{
	int x,y,t;
};
int m;
int a[N][N],dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
bool vis[N][N];
queue<Node>q;
void bfs(){
	q.push({0,0,0});
	vis[0][0]=true;
	while(!q.empty()){
		int x=q.front().x,y=q.front().y,t=q.front().t;q.pop();
		for (int v=0;v<4;v++){
			int x1=x+dx[v],y1=y+dy[v];
			if (0<=x1&&x1<=U&&0<=y1&&y1<=U&&!vis[x1][y1]&&t<a[x1][y1]-1){
				if (a[x1][y1]==inf){
					cout<<t+1;
					return;
				}else{
					vis[x1][y1]=true;
					//cout<<x1<<","<<y1<<"\n";
					q.push({x1,y1,t+1});
				}
			}
		}
	}
	cout<<-1;
}
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>m;
	for (int i=0;i<=U;i++){
		for (int j=0;j<=U;j++)a[i][j]=inf;
	}
	for (int i=1;i<=m;i++){
		int x,y,t;
		cin>>x>>y>>t;
		a[x][y]=min(a[x][y],t);
		a[x+1][y]=min(a[x][y],t);
		if (x>=1)a[x-1][y]=min(a[x][y],t);
		a[x][y+1]=min(a[x][y],t);
		if (y>=1)a[x][y-1]=min(a[x][y],t);
	}
	/*for (int i=0;i<=10;i++){
		for (int j=0;j<=10;j++){
			if (a[i][j]==inf)cout<<'p'<<" ";
			else cout<<a[i][j]<<" ";
		}
		cout<<"\n";
	}*/
	bfs();
}
2024/7/12 20:02
加载中...