Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define li          long
#define ll          long long
#define ull         unsigned long long
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pli         pair<li,li>
#define pll         pair<ll,ll>
#define pb          push_back
#define fo(i,k,n)   for(int i = k;i<n; i++)
#define ro(i,k,n)   for(int i = k; i>=n; i--)
#define tc          int t;cin>>t;while(t--)
#define all(v)      v.begin(),v.end()
#define inf         INT_MAX
#define ninf        INT_MIN
#define W(x)        cout<<x<<endl
#define WW(x,y)     cout<<x<<' '<<y<<endl;
#define in(x)       cin>>x
#define vi          vector<int>
#define vll         vector<long long>
#define vpi         vector<pair<int>>
#define vpll        vector<pair<long long>>
#define vvi         vector<vector<int>>
#define vvll        vector<vector<long long>>
#define vvpi        vector<vector<pair<int,int>>>
#define vvpll       vector<vector<pair<long long>>>
const ll mod1 = 99844353;
const ll mod2 = 1e9+7;
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
} 

template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}

const int mxn = 1e6;
vector<vector<char>> g;
int h,w,k,x1,y1,x2,y2;
struct node{
    int x,y,w;
    node(int x,int y,int z){
        this->x = x,this->y = y,this->w = z;
    }
};
struct comp{
    bool operator()(const node& n1,const node& n2){
        return n1.w<=n2.w;
    }
};
void solve(){
    cin>>h>>w>>k>>x1>>y1>>x2>>y2;
    x1-=1,y1-=1,x2-=1,y2-=1;
    g = vector<vector<char>>(h,vector<char>(w));
    for(int i = 0; i<h; i++){
        for(int j = 0; j<w; j++)cin>>g[i][j];
    }
    vector<vector<int>> dp(h,vector<int>(w,INT_MAX));
    set<node,comp> st;
    st.insert(node(x1,y1,0));
    dp[x1][y1] = 0;
    while(!st.empty()){
        node start = *st.begin();
        st.erase(st.begin());
        if(start.x == x2&&start.y == y2){
            cout<<start.w<<"\n";
            return;
        }
        for(int x = start.x+1; x<=start.x+k&&x<h; x++){
            if(g[x][start.y] == '@')break;
            if(dp[x][start.y]>start.w+1){
                if(st.find(node(x,start.y,dp[x][start.y]))!=st.end())st.erase(node(x,start.y,dp[x][start.y]));
                dp[x][start.y] = start.w+1;
                st.insert(node(x,start.y,dp[x][start.y]));
            }
        }
        for(int x = start.x-1; x>=start.x-k&&x>=0; x--){
            if(g[x][start.y] == '@')break;
            if(dp[x][start.y]>start.w+1){
                if(st.find(node(x,start.y,dp[x][start.y]))!=st.end())st.erase(node(x,start.y,dp[x][start.y]));
                dp[x][start.y] = start.w+1;
                st.insert(node(x,start.y,dp[x][start.y]));
            }
        }
        for(int y = start.y+1; y<=start.y+k&&y<w; y++){
            if(g[start.x][y] == '@')break;
            if(dp[start.x][y]>start.w+1){
                if(st.find(node(start.x,y,dp[start.x][y]))!=st.end())st.erase(node(start.x,y,dp[start.x][y]));
                dp[start.x][y] = start.w+1;
                st.insert(node(start.x,y,dp[start.x][y]));
            }
        }
        for(int y = start.y-1; y>=start.y-k&&y>=0; y--){
            if(g[start.x][y] == '@')break;
            if(dp[start.x][y]>start.w+1){
                if(st.find(node(start.x,y,dp[start.x][y]))!=st.end())st.erase(node(start.x,y,dp[start.x][y]));
                dp[start.x][y] = start.w+1;
                st.insert(node(start.x,y,dp[start.x][y]));
            }
        }
    }
    if(dp[x2][y2] == INT_MAX)cout<<-1<<"\n";
    else cout<<dp[x2][y2]<<"\n";
}

signed main(){
    fastio();
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Compiler output:
a.cc:57:14: error: 'int y1' redeclared as different kind of entity
   57 | int h,w,k,x1,y1,x2,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 'void solve()':
a.cc:70:21: error: no match for 'operator>>' (operand types are 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} and 'double(double) noexcept')
   70 |     cin>>h>>w>>k>>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:70:23: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'double (*)(double) noexcept'
   70 |     cin>>h>>w>>k>>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:70:23: error: invalid conversion from 'double (*)(double) noexcept' to 'short int' [-fpermissive]
   70 |     cin>>h>>w>>k>>x1>>y1>>x2>>y2;
      |                       ^~
      |                       |
      |                       double (*)(double) noexcept
a.cc:70:23: 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:70:23: error: invalid conversion from 'double (*)(double) noexcept' to 'short unsigned int' [-fpermissive]
   70 |     cin>>h>>w>>k>>x1>>y1>>x2>>y2;
      |                       ^~
      |                       |
      |                       double (*)(double) noexcept
a.cc:70:23: 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:70:23: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
   70 |     cin>>h>>w>>k>>x1>>y1>>x2>>y2;
      |                       ^~
      |                       |
      |                       double (*)(double) noexcept
a.cc:70:23: 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:70:23: error: invalid conversion from 'double (*)(double) noexcept' to 'unsigned int' [-fpermissive]
   70 |     cin>>h>>w>>k>>x1>>y1>>x2>>y2;
      |                       ^~
      |                       |
      |                       double (*)(double) noexcept
a.cc:70:23: 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:70:23: error: invalid conversion from 'double (*)(double) noexcept' to 'long int' [-fpermissive]
   70 |     cin>>h>>w>>k>>x1>>y1>>x2>>y2;
      |                       ^~
      |                       |
      |                       double (*)(double) noexcept
a.cc:70:23: 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:70:23: error: invalid conversion from 'double (*)(double) noexcept' to 'long unsigned int' [-fpermissive]
   70 |     cin>>h>>w>>k>>x1>>y1>>x2>>y2;
      |                       ^~
      |                       |
      |                       double (*)(double) noexcept
a.cc:70:23: 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:70:23: error: invalid conversion from 'double (*)(double) noexcept' to 'long long int' [-fpermissive]
   70 |     cin>>h>>w>>k>>x1>>y1>>x2>>y2;
      |                       ^~
      |                       |
      |                       double (*)(double) noexcept
a.cc:70:23: 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:70:23: error: invalid conversion from 'double (*)(double) noexcept' to 'long long unsigned int' [-fpermissive]
   70 |     cin>>h>>w>>k>>x1>>y1>>x2>>y2;
      |                       ^~
      |                       |
      |                       double (*)(double) noexcept
a.cc:70:23: error: cannot bind rvalue '(long long unsigned int)y1' to 'long long unsigned int&'
/usr/include/c++/14/istream:328:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  328 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/14/istream:328:7: note:   conversion of argument 1 would be ill-formed:
a.cc:70:23: error: invalid conversion from 'double (*)(double) noexcept' to 'void*' [-fpermissive]
   70 |     cin>>h>>w>>k>>x1>>y1>>x2>>y2;
      |                       ^~
      |                       |
      |                       double (*)(double) noexcept
a.cc:70:23: error: cannot bind rvalue '(void*)y1' to 'void*&'
/usr/include/c++/14/istream:122:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  122 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:122:7: note:   conversion of argument 1 would be ill-formed:
a.cc:70:23: error: invalid conversion from 'double (*)(double) noexcept' to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'} [-fpermissive]
   70 |     cin>>h>>w>>k>>x1>>y1>>x2>>y2;
      |                       ^~
      |                       |
      |                       double (*)(double) noexcept
/usr/include/c++/14/istream:126:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>; __ios_type = std::basic_ios<char>]' (near match)
  126 |       operator>>(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:126:7: note:   co