Language: C++

#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int h,w,k,x1,y1,x2,y2;
    cin >> h >> w >> k >> x1 >> y1 >> x2 >> y2;
    x1--; x2--; y1--; y2--;
    vs c(h);
    cin >> c;
    vector<set<int>> row(h),col(w);
    rep(i,h) rep(j,w) if(c[i][j] == '@') {
        row[i].insert(j);
        col[j].insert(i);
    }
    rep(i,h) {
        row[i].insert(-1);
        row[i].insert(w);
    }
    rep(i,w) {
        col[i].insert(-1);
        col[i].insert(h);
    }
    vvi dist(h,vi(w,inf));
    dist[x1][y1] = 0;
    queue<P> q;
    q.emplace(x1,y1);
    while(q.size()) {
        auto [x,y] = q.front();
        q.pop();
        // up
        {
            auto it = col[y].lower_bound(x);
            it--;
            int nx = x-1;
            while(nx > *it and x-nx <= k) {
                if (chmin(dist[nx][y], dist[x][y] + 1)) {
                    q.emplace(nx, y);
                }
                nx--;
            }
        }
        // down
        {
            auto it = col[y].lower_bound(x);
            int nx = x+1;
            while(nx < *it and nx-x <= k) {
                if(chmin(dist[nx][y],dist[x][y]+1) {
                    q.emplace(nx, y);
                }
                nx++;
            }
        }
        // left
        {
            auto it = row[x].lower_bound(y);
            it--;
            int ny = y-1;
            while(ny > *it and y-ny <= k) {
                if(chmin(dist[x][ny],dist[x][y]+1)) {
                    q.emplace(x, ny);
                }
                ny--;
            }
        }
        // right
        {
            auto it = row[x].lower_bound(y);
            int ny = y+1;
            while(ny < *it and ny-y <= k) {
                if(chmin(dist[x][ny],dist[x][y]+1) {
                    q.emplace(x, ny);
                }
                ny++;
            }
        }
        row[x].insert(y);
        col[y].insert(x);
    }
    cout << (dist[x2][y2] == inf ? -1 : dist[x2][y2]) << endl;
}

                   

Compiler output:
a.cc: In function 'int main()':
a.cc:78:51: error: expected ';' before '{' token
   78 |                 if(chmin(dist[nx][y],dist[x][y]+1) {
      |                                                   ^~
      |                                                   ;
a.cc:81:21: error: expected ')' before ';' token
   81 |                 nx++;
      |                     ^
      |                     )
a.cc:78:19: note: to match this '('
   78 |                 if(chmin(dist[nx][y],dist[x][y]+1) {
      |                   ^
a.cc:101:51: error: expected ';' before '{' token
  101 |                 if(chmin(dist[x][ny],dist[x][y]+1) {
      |                                                   ^~
      |                                                   ;
a.cc:104:21: error: expected ')' before ';' token
  104 |                 ny++;
      |                     ^
      |                     )
a.cc:101:19: note: to match this '('
  101 |                 if(chmin(dist[x][ny],dist[x][y]+1) {
      |                   ^