玄关,tle两个点,wa一个点
查看原帖
玄关,tle两个点,wa一个点
995853
lwxxs楼主2024/4/8 21:25

提交测试点

#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> pii;
const int N=1e3+10;
struct node{
   pii point;
   int w;
};
char g[N][N];
int a[N][N];
int dist[N][N];
int s[N][N];
int st1[N][N];
pii st,ed;
int n,m,k;
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
void bfs(){
    queue<node> q;
    memset(dist,-0x3f,sizeof dist);
    s[st.first][st.second]=1;
    dist[st.first][st.second]=a[st.first][st.second];
    q.push({{st.first,st.second},a[st.first][st.second]});
    while(q.size()){
        auto t=q.front();
        q.pop();
        int x=t.point.first,y=t.point.second,w=t.w;
        if(x==ed.first&&y==ed.second){
            cout<<"Yes"<<endl;
           exit(0);
        }
        for(int i=0;i<4;i++){
            int x1=x+dx[i];
            int y1=y+dy[i];
            if(x1<=0||x1>n||y1<=0||y1>m)continue;
            if(g[x1][y1]=='#')continue;
            if(dist[x1][y1]<w-1&&w>0){
                if(a[x1][y1]){
                    if(w-1>a[x1][y1]){
                        q.push({{x1,y1},w-1});
                        st1[x1][y1]=true;
                    }
                    else if(!st1[x][y]){
                       q.push({{x1, y1}, a[x1][y1]});
                       st1[x][y]=true;
                    }
                }
                else{
                    dist[x1][y1]=w-1;
                    q.push({{x1,y1},dist[x1][y1]});
                }
            }
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++){
            cin>>g[i][j];
            if(g[i][j]=='S')st={i,j};
            else if(g[i][j]=='T')ed={i,j};
        }
    cin>>k;
    while(k--){
        int x,y,z;
        cin>>x>>y>>z;
        a[x][y]=z;
    }
    bfs();
    cout<<"No"<<endl;
}
2024/4/8 21:25
加载中...