Language: C++

#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define pb push_back
#define SZ(a) ((int)a.size())

 
const int oo = 1e9;
const int Maxn = 1e5;
const int N = 2e5 + 100;
const double PI = (-2.00) * asin(-1);
 
typedef pair<int, pair<int, int> > iii;
typedef pair<int, int> ii;    


int n, m, k, x1, x2, y1, y2;
vector< vector<int> > check, a; 
vector<ii> vi[2];

int solve() {
    int lst = 0, nxt = 1;
    check[x1][y1] = 1;
    vi[lst].pb({x1, y1});
    int cnt = 0;
    while(SZ(vi[lst]) > 0)  {
        cnt += 1;
        vi[nxt].clear();
        for(auto v: vi[lst]) {
            check[v.fi][v.se] = 1;
            if(v == ii(x2, y2)) return cnt - 1;
        }
        for(auto v: vi[lst]) {
            for(int i = v.fi - 1; i >= 1 && v.fi - i <= k; i -= 1) {
                if(a[i][v.se] || check[i][v.se]) break;
                vi[nxt].pb({i, v.se});
            }
            for(int i = v.fi + 1; i <= n && i - v.fi <= k; i ++) {
                if(a[i][v.se] || check[i][v.se]) break;
                vi[nxt].pb({i, v.se});
            }
            // columns
            for(int i = v.se - 1; i >= 1 && v.se - i <= k; i -= 1) {
                if(a[v.fi][i] || check[v.fi][i]) break;
                vi[nxt].pb({v.fi, i});
            }
            for(int i = v.se + 1; i <= m && i - v.se <= k; i += 1) {
                if(a[v.fi][i] || check[v.fi][i]) break;
                vi[nxt].pb({v.fi, i});
            }
        }
        swap(lst, nxt);
    }
    return -1;
}
signed main()
{
    #ifdef TEST
        freopen("test.inp", "r", stdin);
    #endif // TEST  
    ios_base::sync_with_stdio(false);                                      
    cin.tie(0); cout.tie(0);

    // 0 = up
    // 1 = down
    // 2 = right
    // 3 = left
    cin >> n >> m >> k;
    a.resize(n + 10);
    FOR(i, 1, n) {
        FOR(j, 1, m + 10) a[i].pb(0);
    }
    check.resize(n + 10);
    FOR(i, 1, n) FOR(j, 1, m + 10) check[i].pb(0);

    cin >> x1 >> y1 >> x2 >> y2;
    FOR(i, 1, n)    {
        FOR(j,1, m) {
            char x; cin >> x;
            a[i][j] = (x == '@');
        }
    }
    cout << solve();
}


Compiler output:
a.cc:21:22: error: 'int y1' redeclared as different kind of entity
   21 | int n, m, k, x1, x2, y1, y2;
      |                      ^~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:257:1: note: previous declaration 'double y1(double)'
  257 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc: In function 'int solve()':
a.cc:27:15: error: invalid conversion from 'double (*)(double) noexcept' to 'std::vector<int>::size_type' {aka 'long unsigned int'} [-fpermissive]
   27 |     check[x1][y1] = 1;
      |               ^~
      |               |
      |               double (*)(double) noexcept
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
a.cc:28:15: error: no matching function for call to 'std::vector<std::pair<int, int> >::push_back(<brace-enclosed initializer list>)'
   28 |     vi[lst].pb({x1, y1});
      |     ~~~~~~~~~~^~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; value_type = std::pair<int, int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc: In function 'int main()':
a.cc:80:15: error: no match for 'operator>>' (operand types are 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} and 'double(double) noexcept')
   80 |     cin >> x1 >> y1 >> x2 >> y2;
      |     ~~~~~~~~~ ^~ ~~
      |         |        |
      |         |        double(double) noexcept
      |         std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}
In file included from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  170 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:170:7: note:   conversion of argument 1 would be ill-formed:
a.cc:80:18: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'double (*)(double) noexcept'
   80 |     cin >> x1 >> y1 >> x2 >> y2;
      |                  ^~
/usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  174 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:174:7: note:   conversion of argument 1 would be ill-formed:
a.cc:80:18: error: invalid conversion from 'double (*)(double) noexcept' to 'short int' [-fpermissive]
   80 |     cin >> x1 >> y1 >> x2 >> y2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:80:18: error: cannot bind rvalue '(short int)y1' to 'short int&'
/usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  177 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:177:7: note:   conversion of argument 1 would be ill-formed:
a.cc:80:18: error: invalid conversion from 'double (*)(double) noexcept' to 'short unsigned int' [-fpermissive]
   80 |     cin >> x1 >> y1 >> x2 >> y2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:80:18: error: cannot bind rvalue '(short unsigned int)y1' to 'short unsigned int&'
/usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  181 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:181:7: note:   conversion of argument 1 would be ill-formed:
a.cc:80:18: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
   80 |     cin >> x1 >> y1 >> x2 >> y2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:80:18: error: cannot bind rvalue '(int)y1' to 'int&'
/usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  184 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:184:7: note:   conversion of argument 1 would be ill-formed:
a.cc:80:18: error: invalid conversion from 'double (*)(double) noexcept' to 'unsigned int' [-fpermissive]
   80 |     cin >> x1 >> y1 >> x2 >> y2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:80:18: error: cannot bind rvalue '(unsigned int)y1' to 'unsigned int&'
/usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:188:7: note:   conversion of argument 1 would be ill-formed:
a.cc:80:18: error: invalid conversion from 'double (*)(double) noexcept' to 'long int' [-fpermissive]
   80 |     cin >> x1 >> y1 >> x2 >> y2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:80:18: error: cannot bind rvalue '(long int)y1' to 'long int&'
/usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:192:7: note:   conversion of argument 1 would be ill-formed:
a.cc:80:18: error: invalid conversion from 'double (*)(double) noexcept' to 'long unsigned int' [-fpermissive]
   80 |     cin >> x1 >> y1 >> x2 >> y2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:80:18: error: cannot bind rvalue '(long unsigned int)y1' to 'long unsigned int&'
/usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  199 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:199:7: note:   conversion of argument 1 would be ill-formed:
a.cc:80:18: error: invalid conversion from 'double (*)(double) noexcept' to 'long long int' [-fpermissive]
   80 |     cin >> x1 >> y1 >> x2 >> y2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:80:18: error: cannot bind rvalue '(long long int)y1' to 'long long int&'
/usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  203 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:203:7: note:   conversion of argument 1 would be ill-formed:
a.cc:80:18: error: invalid conversion from 'double (*)(double) noexcept' to 'long long unsigned int' [-fpermissive]
   80 |     cin >> x1 >> y1 >> x2 >> y2;
      |                  ^~
      |                  |
      |                  double (*)(double) noexcept
a.cc:80:18: error: cannot bind rvalue '(long long unsigned in