266242026-04-04 10:55:28KristófLegközelebbi mezőkcpp17Forditási hiba
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;

bool lehet(pair<int,int> pos,vector<vector<char>> &adj,int &n,int &m)
{
if(pos.first<0 || pos.first>=n || pos.second<0 || pos.second>=m)return false;
return true;
}

int main()
{
    int n,m;
    cin>>n>>m;
    vector<vector<char>> adj(n,vector<char> (m));
    pair<int,int> posA,posB;
    for(int i=0;i<n;i++)
        {
        for(int j=0;j<m;j++)
            {
            cin>>adj[i][j];
            if(adj[i][j]=='A')posA={i,j};
            if(adj[i][j]=='B')posB={i,j};
            }
        }
    queue<pair<int,int>> q;
    q.push(posA);

    map<pair<int,int>,bool> vis;
    vis[posA]=true;
    queue<pair<int,int>> q2;
    vector<vector<int>> dist(n,vector<int> (m,INT_MAX));
    map<pair<int,int>,bool> vis2;
    while(q.size())
        {
        dist[q.front().first][q.front().second]=0;
        q2.push(q.front());
        vis2[q.front()]=true;
        auto [x,y]=q.front();q.pop();

        if(x==posB.first && y==posB.second)
            {
            cout<<0;
            return 0;
            }
        if(!vis[{x-1,y}] && lehet({x-1,y},adj,n,m) && adj[x-1][y]!='#')
            {
            vis[{x-1,y}]=true;
            q.push({x-1,y});
            }
        if(!vis[{x+1,y}] && lehet({x+1,y},adj,n,m) && adj[x+1][y]!='#')
            {
            vis[{x+1,y}]=true;
            q.push({x+1,y});
            }
        if(!vis[{x,y-1}] && lehet({x,y-1},adj,n,m) && adj[x][y-1]!='#')
            {
            vis[{x,y-1}]=true;
            q.push({x,y-1});
            }
        if(!vis[{x,y+1}] && lehet({x,y+1},adj,n,m) && adj[x][y+1]!='#')
            {
            vis[{x,y+1}]=true;
            q.push({x,y+1});
            }
        }
    while(q2.size())
        {
        auto [x,y]=q2.front();q2.pop();
        if(!vis2[{x-1,y}] && lehet({x-1,y},adj,n,m))
            {
            vis2[{x-1,y}]=true;
            q2.push({x-1,y});
            dist[x-1][y]=min(dist[x-1][y],dist[x][y]+1);
            }
        if(!vis2[{x+1,y}] && lehet({x+1,y},adj,n,m))
            {
            vis2[{x+1,y}]=true;
            q2.push({x+1,y});
            dist[x+1][y]=min(dist[x+1][y],dist[x][y]+1);
            }
        if(!vis2[{x,y-1}] && lehet({x,y-1},adj,n,m))
            {
            vis2[{x,y-1}]=true;
            q2.push({x,y-1});
            dist[x][y-1]=min(dist[x][y-1],dist[x][y]+1);
            }
        if(!vis2[{x,y+1}] && lehet({x,y+1},adj,n,m))
            {
            vis2[{x,y+1}]=true;
            q2.push({x,y+1});
            dist[x][y+1]=min(dist[x][y+1],dist[x][y]+1);
            }
        }
    int ans=INT_MAX;
    while(q.size())q.pop();
    vis.clear();
    q.push(posB);
    vis[posB]=true;
    while(q.size())
        {
        auto [x,y]=q.front();q.pop();
        if(!vis[{x-1,y}] && lehet({x-1,y},adj,n,m) && adj[x-1][y]!='#')
            {
            vis[{x-1,y}]=true;
            q.push({x-1,y});
            ans=min(ans,dist[x-1][y]);
            }
        if(!vis[{x+1,y}] && lehet({x+1,y},adj,n,m) && adj[x+1][y]!='#')
            {
            vis[{x+1,y}]=true;
            q.push({x+1,y});
            ans=min(ans,dist[x+1][y]);
            }
        if(!vis[{x,y-1}] && lehet({x,y-1},adj,n,m) && adj[x][y-1]!='#')
            {
            vis[{x,y-1}]=true;
            q.push({x,y-1});
            ans=min(ans,dist[x][y-1]);
            }
        if(!vis[{x,y+1}] && lehet({x,y+1},adj,n,m) && adj[x][y+1]!='#')
            {
            vis[{x,y+1}]=true;
            q.push({x,y+1});
            ans=min(ans,dist[x][y+1]);
            }
        }
    cout<<ans;
    return 0;
}
Forditási hiba
open /var/local/lib/isolate/408/box/a.out: no such file or directory
main.cpp: In function 'int main()':
main.cpp:34:47: error: 'INT_MAX' was not declared in this scope
   34 |     vector<vector<int>> dist(n,vector<int> (m,INT_MAX));
      |                                               ^~~~~~~
main.cpp:5:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    4 | #include <map>
  +++ |+#include <climits>
    5 | using namespace std;