Language: C++

// 6/14 リアルタイム参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int H, W, K;
int sh, sw, gh, gw;
vector<string> field;

// vector<vector<bool>> seen;
// vector<vector<ll>> dist;

const int dh[4] = {1, -1, 0, 0};
const int dw[4] = {0, 0, 1, -1};

int main() {
    cin >> H >> W >> K;
    cin >> sh >> sw >> gh >> gw;
    sh--;
    sw--;
    gh--;
    gw--;

    field.resize(H);
    rep(h, H) {
        cin >> field[h];
    }

    // memset(seen, 0, sizeof(seen));

    vector<vector<ll>> dist(H, vector<ll>(W, -1));  // 未訪問
    queue<P> que;

    dist[sh][sw] = 0;
    que.push({sh, sw});

    while (!que.empty()) {
        P p = que.front();
        que.pop();

        // pから辿れる場所を全部たどる。
        rep(i, 4) {
            int count = 0;

            for (int j = 1; j <= K; j++) {
                int nh = p.first + dh[i] * j;
                int nw = p.second + dw[i] * j;

                // 場外アウトしたり、ハスの場合はbreak。それ以上伸ばさない。
                if (nh < 0 || nh >= H || nw < 0 || nw >= W) break;
                if (field[nh][nw] == '@') break;

                // 移動先が探索済みの時もブレイク。
                if (dist[nh][nw] != -1) {
                    count++;

                    if (count > 100) break;
                    continue;
                }

                dist[nh][nw] = dist[p.first][p.second] + 1;
                que.push({nh, nw});
            }
        }

    }

    // rep(h, H) {
    //     rep(w, W) {
    //         cout << dist[h][w] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dist[gh][gw] << endl;
}// 6/14 リアルタイム参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int H, W, K;
int sh, sw, gh, gw;
vector<string> field;

// vector<vector<bool>> seen;
// vector<vector<ll>> dist;

const int dh[4] = {1, -1, 0, 0};
const int dw[4] = {0, 0, 1, -1};

int main() {
    cin >> H >> W >> K;
    cin >> sh >> sw >> gh >> gw;
    sh--;
    sw--;
    gh--;
    gw--;

    field.resize(H);
    rep(h, H) {
        cin >> field[h];
    }

    // memset(seen, 0, sizeof(seen));

    vector<vector<ll>> dist(H, vector<ll>(W, -1));  // 未訪問
    queue<P> que;

    dist[sh][sw] = 0;
    que.push({sh, sw});

    while (!que.empty()) {
        P p = que.front();
        que.pop();

        // pから辿れる場所を全部たどる。
        rep(i, 4) {
            int count = 0;

            for (int j = 1; j <= K; j++) {
                int nh = p.first + dh[i] * j;
                int nw = p.second + dw[i] * j;

                // 場外アウトしたり、ハスの場合はbreak。それ以上伸ばさない。
                if (nh < 0 || nh >= H || nw < 0 || nw >= W) break;
                if (field[nh][nw] == '@') break;

                // 移動先が探索済みの時もブレイク。
                if (dist[nh][nw] != -1) {
                    count++;

                    if (count > 100) break;
                    continue;
                }

                dist[nh][nw] = dist[p.first][p.second] + 1;
                que.push({nh, nw});
            }
        }

    }

    // rep(h, H) {
    //     rep(w, W) {
    //         cout << dist[h][w] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dist[gh][gw] << endl;
}

Compiler output:
a.cc:87:5: error: redefinition of 'int H'
   87 | int H, W, K;
      |     ^
a.cc:9:5: note: 'int H' previously declared here
    9 | int H, W, K;
      |     ^
a.cc:87:8: error: redefinition of 'int W'
   87 | int H, W, K;
      |        ^
a.cc:9:8: note: 'int W' previously declared here
    9 | int H, W, K;
      |        ^
a.cc:87:11: error: redefinition of 'int K'
   87 | int H, W, K;
      |           ^
a.cc:9:11: note: 'int K' previously declared here
    9 | int H, W, K;
      |           ^
a.cc:88:5: error: redefinition of 'int sh'
   88 | int sh, sw, gh, gw;
      |     ^~
a.cc:10:5: note: 'int sh' previously declared here
   10 | int sh, sw, gh, gw;
      |     ^~
a.cc:88:9: error: redefinition of 'int sw'
   88 | int sh, sw, gh, gw;
      |         ^~
a.cc:10:9: note: 'int sw' previously declared here
   10 | int sh, sw, gh, gw;
      |         ^~
a.cc:88:13: error: redefinition of 'int gh'
   88 | int sh, sw, gh, gw;
      |             ^~
a.cc:10:13: note: 'int gh' previously declared here
   10 | int sh, sw, gh, gw;
      |             ^~
a.cc:88:17: error: redefinition of 'int gw'
   88 | int sh, sw, gh, gw;
      |                 ^~
a.cc:10:17: note: 'int gw' previously declared here
   10 | int sh, sw, gh, gw;
      |                 ^~
a.cc:89:16: error: redefinition of 'std::vector<std::__cxx11::basic_string<char> > field'
   89 | vector<string> field;
      |                ^~~~~
a.cc:11:16: note: 'std::vector<std::__cxx11::basic_string<char> > field' previously declared here
   11 | vector<string> field;
      |                ^~~~~
a.cc:94:11: error: redefinition of 'const int dh [4]'
   94 | const int dh[4] = {1, -1, 0, 0};
      |           ^~
a.cc:16:11: note: 'const int dh [4]' previously defined here
   16 | const int dh[4] = {1, -1, 0, 0};
      |           ^~
a.cc:95:11: error: redefinition of 'const int dw [4]'
   95 | const int dw[4] = {0, 0, 1, -1};
      |           ^~
a.cc:17:11: note: 'const int dw [4]' previously defined here
   17 | const int dw[4] = {0, 0, 1, -1};
      |           ^~
a.cc:97:5: error: redefinition of 'int main()'
   97 | int main() {
      |     ^~~~
a.cc:19:5: note: 'int main()' previously defined here
   19 | int main() {
      |     ^~~~