Language: C++

#include<bits/stdc++.h>
using namespace std;

struct cell
{
    int num;
    //bool ispath;
    bool visited;
};

int main()
{
    int h,w;
    cin >> h >> w;
    int ch,cw,dh,dw;
    cin >> ch >> cw >> dh >> dw;
    ch--;cw--;dh--;dw--;

    cell maze[h+4][w+4];//厚さ2の壁を外周に設置
    ch+=2;cw+=2;dh+=2;dw+=2;
    for (int i = 2; i < h+2; i++)
    {
        for (int j = 2; j < w+2; j++)
        {
            char s;
            cin >> s;
            if (s=='.')
            {
                maze[i][j].visited = false;
            }
            else
            {
                maze[i][j].visited = true;
            }
            maze[i][j].num = -1;
        }
    }
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < w+4; j++)
        {
            maze[i][j].visited = true;
        }
    }
    for (int i = 0; i < h+4; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            maze[i][j].visited = true;
        }
    }
    for (int i = h+2; i < h+4; i++)
    {
        for (int j = 0; j < w+4; j++)
        {
            maze[i][j].visited = true;
        }
    }
    for (int i = 0; i < h+4; i++)
    {
        for (int j = w+2; j < w+4; j++)
        {
            maze[i][j].visited = true;
        }
    }

    //bfs
    queue<pair<int,int>> Q;
    set<pair<int,int>> S={};//ワープ候補のマスの集合
    Q.push(make_pair(ch,cw));
    maze[ch][cw].num = 0;
    while (!Q.empty() and !S.empty())
    {
        if (!S.empty())
        {
            Q.push(*S.begin());
            S.erase(*S.begin());
        }
        
        pair<int,int> now = Q.front();
        Q.pop();
        int nowi = now.first;
        int nowj = now.second;
        //徒歩圏内
        if (maze[nowi+1][nowj].visited == false)
        {
            maze[nowi+1][nowj].visited = true;
            maze[nowi+1][nowj].num = maze[nowi][nowj].num;
            Q.push({nowi+1,nowj});
            S.erase({nowi+1,nowj});
        }
        if (maze[nowi-1][nowj].visited == false)
        {
            maze[nowi-1][nowj].visited = true;
            maze[nowi-1][nowj].num = maze[nowi][nowj].num;
            Q.push(make_pair<nowi-1,nowj>);
            S.erase(make_pair<nowi-1,nowj>);
        }
        if (maze[nowi][nowj+1].visited == false)
        {
            maze[nowi][nowj+1].visited = true;
            maze[nowi][nowj+1].num = maze[nowi][nowj].num;
            Q.push(make_pair<nowi,nowj+1>);
            S.erase(make_pair<nowi,nowj+1>);
        }
        if (maze[nowi][nowj-1].visited == false)
        {
            maze[nowi][nowj-1].visited = true;
            maze[nowi][nowj-1].num = maze[nowi][nowj].num;
            Q.push(make_pair<nowi,nowj-1>);
            S.erase(make_pair<nowi,nowj-1>);
        }
        //ワープ圏内
        if (maze[nowi+2][nowj].visited == false)
        {
            maze[nowi+2][nowj].num = maze[nowi][nowj].num + 1;
            S.insert(make_pair(nowi+2,nowj));
        }
        if (maze[nowi-2][nowj].visited == false)
        {
            maze[nowi-2][nowj].num = maze[nowi][nowj].num + 1;
            S.insert(make_pair(nowi-2,nowj));
        }
        if (maze[nowi][nowj+2].visited == false)
        {
            maze[nowi][nowj+2].num = maze[nowi][nowj].num + 1;
            S.insert(make_pair(nowi,nowj+2));
        }
        if (maze[nowi][nowj-2].visited == false)
        {
            maze[nowi][nowj-2].num = maze[nowi][nowj].num + 1;
            S.insert(make_pair(nowi,nowj-2));
        }
        if (maze[nowi+1][nowj+1].visited == false)
        {
            maze[nowi+1][nowj+1].num = maze[nowi][nowj].num + 1;
            S.insert(make_pair(nowi+1,nowj+1));
        }
        if (maze[nowi+1][nowj-1].visited == false)
        {
            maze[nowi+1][nowj-1].num = maze[nowi][nowj].num + 1;
            S.insert(make_pair(nowi+1,nowj-1));
        }
        if (maze[nowi-1][nowj+1].visited == false)
        {
            maze[nowi-1][nowj+1].num = maze[nowi][nowj].num + 1;
            S.insert(make_pair(nowi-1,nowj+1));
        }
        if (maze[nowi-1][nowj-1].visited == false)
        {
            maze[nowi-1][nowj-1].num = maze[nowi][nowj].num + 1;
            S.insert(make_pair(nowi-1,nowj-1));
        }
        //break
        if (nowi==dh and nowj==dw)
        {
            break;
        }
        
    }
    cout << maze[dh][dw].num << endl;
    
    
}

Compiler output:
a.cc: In function 'int main()':
a.cc:96:35: error: the value of 'nowi' is not usable in a constant expression
   96 |             Q.push(make_pair<nowi-1,nowj>);
      |                                   ^
a.cc:82:13: note: 'int nowi' is not const
   82 |         int nowi = now.first;
      |             ^~~~
a.cc:96:19: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(<unresolved overloaded function type>)'
   96 |             Q.push(make_pair<nowi-1,nowj>);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_queue.h:283:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, int>]'
  283 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:283:30: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const std::queue<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
  283 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:288:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, int>]'
  288 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:288:25: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::queue<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:97:36: error: the value of 'nowi' is not usable in a constant expression
   97 |             S.erase(make_pair<nowi-1,nowj>);
      |                                    ^
a.cc:82:13: note: 'int nowi' is not const
   82 |         int nowi = now.first;
      |             ^~~~
a.cc:97:20: error: no matching function for call to 'std::set<std::pair<int, int> >::erase(<unresolved overloaded function type>)'
   97 |             S.erase(make_pair<nowi-1,nowj>);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/set:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:158:
/usr/include/c++/14/bits/stl_set.h:656:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(const_iterator) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator]'
  656 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_set.h:656:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::set<std::pair<int, int> >::const_iterator' {aka 'std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator'}
  656 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:686:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; size_type = long unsigned int; key_type = std::pair<int, int>]'
  686 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/14/bits/stl_set.h:686:29: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const std::set<std::pair<int, int> >::key_type&' {aka 'const std::pair<int, int>&'}
  686 |       erase(const key_type& __x)
      |             ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:708:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(const_iterator, const_iterator) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator]'
  708 |       erase(const_iterator __first, const_iterator __last)
      |       ^~~~~
/usr/include/c++/14/bits/stl_set.h:708:7: note:   candidate expects 2 arguments, 1 provided
a.cc:103:40: error: the value of 'nowj' is not usable in a constant expression
  103 |             Q.push(make_pair<nowi,nowj+1>);
      |                                        ^
a.cc:83:13: note: 'int nowj' is not const
   83 |         int nowj = now.second;
      |             ^~~~
a.cc:103:19: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(<unresolved overloaded function type>)'
  103 |             Q.push(make_pair<nowi,nowj+1>);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:283:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, int>]'
  283 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:283:30: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const std::queue<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
  283 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:288:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, int>]'
  288 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:288:25: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::queue<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:104:41: error: the value of 'nowj' is not usable in a constant expression
  104 |             S.erase(make_pair<nowi,nowj+1>);
      |                                         ^
a.cc:83:13: note: 'int nowj' is not const
   83 |         int nowj = now.second;
      |             ^~~~
a.cc:104:20: error: no matching function for call to 'std::set<std::pair<int, int> >::erase(<unresolved overloaded function type>)'
  104 |             S.erase(make_pair<nowi,nowj+1>);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:656:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(const_iterator) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator]'
  656 |       erase(const_iterator __position)
      |       ^~~~~
/usr/include/c++/14/bits/stl_set.h:656:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::set<std::pair<int, int> >::const_iterator' {aka 'std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator'}
  656 |       erase(const_iterator __position)
      |             ~~~~~~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:686:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; size_type = long unsigned int; key_type = std::pair<int, int>]'
  686 |       erase(const key_type& __x)
      |       ^~~~~
/usr/include/c++/14/bits/stl_set.h:686:29: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'const std::set<std::pair<int, int> >::key_type&' {aka 'const std::pair<int, int>&'}
  686 |       erase(const key_type& __x)
      |             ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_set.h:708:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::erase(const_iterator, const_iterator) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pai