Language: C++

#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

struct you{
    int ma;
    set<P> st;
};

int main() {
    int h, w, k; cin >> h >> w >> k;
    vector<int> sg(4);
    rep(i,4){
        int a; cin >> a;
        sg[i] = a-1;
    }
    vector<vector<int>> maze(h,vector<int>(w));
    rep(i,h){
        rep(j,w){
            char c; cin >> c;
            if (c == '@') maze[i][j] = 1;
            else maze[i][j] = 0;
        }
    }
    vector<vector<int>> ans(h,vector<int>(w,INF));
    queue<P> que;
    que.push(P(sg[0],sg[1]));
    ans[sg[0]][sg[1]] = 0;
    while (!que.empty()){
        P p = que.front(); que.pop();
        int x = p.first;
        int y = p.second;
        int sc = ans[x][y] + 1;
        int c = 1;
        while (x+c < h && ans[x+c][y] >= sc && maze[x+c][y] == 0 && c <= k){
            que.push(P(x+c,y));
            ans[x+c][y] = min(ans[x+c][y],sc);
            c++;
        }
        c = 1;
        while (x - c >= 0 && ans[x-c][y] >= sc && maze[x-c][y] == 0 && c <= k){
            que.push(P(x-c,y));
            ans[x-c][y] = min(ans[x-c][y],sc);
            c++;
        }
        c = 1;
        while (y + c < w && ans[x][y+c] >=sc && maze[x][y+c] == 0 && c <= k){
            que.push(P(x,y+c));
            ans[x][y+c] = min(ans[x][y+c],sc);
            c++;
        }
        c = 1;
        while (y - c >= 0 && ans[x][y-c] >= sc && maze[x][y-c] == 0 && c <= k){
            que.push(P(x,y-c));
            ans[x][y-c] = min(ans[x][y-c],sc);
            c++;
        }
        if (ans[sg[2][sg[3]] != INF){
            cout << ans[sg[2]][sg[3]] << endl;
            return 0;
        }
    }
    if (ans[sg[2]][sg[3]] == INF) cout << -1 << endl;
    else cout << ans[sg[2]][sg[3]] << endl;
    /*
    rep(i,h){
        rep(j,w){
            if (ans[i][j] != INF) cout << ans[i][j] << " ";
            else cout << "! ";
        }
        cout << endl;
    }
    */
}

Compiler output:
a.cc: In function 'int main()':
a.cc:95:22: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}[__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type {aka int}]' for array subscript
   95 |         if (ans[sg[2][sg[3]] != INF){
      |                      ^
a.cc:95:36: error: expected ']' before ')' token
   95 |         if (ans[sg[2][sg[3]] != INF){
      |                                    ^
      |                                    ]