yuanzhenxiang1117 @ 2024-01-27 19:47:20
#include<bits/stdc++.h>
#define MIN(x,y,t) death[x][y]=min(death[x][y],t)
using namespace std;
int x,y,t;
int T[307][307],death[307][307];
int m,ans=10000;
int walk[4][2]={{0,1},{0,-1},{-1,0},{1,0}};
struct coord{
int hx,hy;
};
queue<coord> q;
int main(){
for(int i=0;i<301;i++){
for(int j=0;j<301;j++){
T[i][j]=-1;
}
}
for(int i=0;i<301;i++){
for(int j=0;j<301;j++){
death[i][j]=99999;
}
}
cin>>m;
for(int i=1;i<=m;i++){
cin>>x>>y>>t;
MIN(x,y,t);
for(int k=0;k<4;k++){
MIN(x+walk[k][0],y+walk[k][1],t);
}
}
coord tmp={0,0};
q.push(tmp);
T[0][0]=0;
while(!q.empty()){
coord u=q.front();
int ux=u.hx;
int uy=u.hy;
q.pop();
for(int k=0;k<4;k++){
int x=ux+walk[k][0];
int y=uy+walk[k][1];
if(x<0||y<0||T[x][y]!=-1||T[ux][uy]+1>=death[x][y])
continue;
T[x][y]=T[ux][uy]+1;
tmp={x,y};
q.push(tmp);
}
}
for(int i=0;i<301;i++){
for(int j=0;j<301;j++){
if(death[i][j]>1000&&T[i][j]!=-1)
ans=min(ans,T[i][j]);
}
}
if(ans==10000) cout<<-1;
else cout<<ans;
return 0;
}
by WindowsWKP @ 2024-01-28 07:03:30
关 O2
by yuanzhenxiang1117 @ 2024-01-28 08:26:06
@WindowsWKP 为啥不关O2会RE
by liuchengle2023 @ 2024-01-29 15:00:47
@yuanzhenxiang1117 O2这个东西,随性的嘞
by yuanzhenxiang1117 @ 2024-01-29 18:35:34
@liuchengle2023 可是我在另一个平台上评测时没有O2开关然后就全部运行错误了