求助!没有输出

P2895 [USACO08FEB] Meteor Shower S

zcayyds @ 2021-06-05 13:13:37

#include<bits/stdc++.h>
using namespace std;
queue< pair<int,int> >q;
int m,T[50005],X[50005],Y[50005];
int v[400][400],at[400][400],a[400][400];
int dx[5]={0,0,1,-1};
int dy[5]={1,-1,0,0};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    for(int i=0;i<=400;i++){
        for(int j=0;j<=400;j++)
            a[i][j]=INT_MAX;

    }
    cin>>m;
    for(int i=1;i<=m;i++){
        cin>>T[i]>>X[i]>>Y[i];
        if(a[X[i]][Y[i]]>T[i])a[X[i]][Y[i]]=T[i];
        if(a[X[i]+1][Y[i]]>T[i])a[X[i]+1][Y[i]]=T[i];
        if(a[X[i]-1][Y[i]]>T[i])a[X[i]-1][Y[i]]=T[i];
        if(a[X[i]][Y[i]-1]>T[i])a[X[i]][Y[i]-1]=T[i];
        if(a[X[i]][Y[i]+1]>T[i])a[X[i]][Y[i]+1]=T[i];
    }
    memset(v,0,sizeof(v));
    q.push(make_pair(0,0));
    v[0][0]=1;
    at[0][0]=0;
    while(!q.empty()){
        q.pop();
        int x=q.front().first;
        int y=q.front().second;
        for(int i=0;i<4;i++){

            int tx=x+dx[i];
            int ty=y+dy[i];
            at[tx][ty]=at[x][y]+1;          
            if(tx>=0&&ty>=0&&v[tx][ty]==0&&a[tx][ty]>at[tx][ty]){
                if(a[tx][ty]==INT_MAX){
                    cout<<at[tx][ty];
                    return 0;
                }
                else{
                    v[tx][ty]=1;
                    q.push(make_pair(tx,ty));
                }
            }
        }
    }
    cout<<"--"<<-1;
    return 0;
}

by AlexFad @ 2021-06-09 08:08:04

 int tx=x+dx[i];
 int ty=y+dy[i];
 at[tx][ty]=at[x][y]+1;

at数组溢出


|