Language: C++

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

const LL mod = 998244353;

int n, m, k;
int x1, y1, x2, y2;
vector<string> s;
vector<vector<int>> vis, nxt[4];

int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};

int run() {
  queue<pair<int, int>> q;
  q.push({x1, y1});
  vis[x1][y1] = 0;

  while (q.size() > 0) {
    int x = q.front().first;
    int y = q.front().second;
    int w = vis[x][y];
    q.pop();

    for (int i = 0; i < 4; i++) {
      int nx = x, ny = y;
      int maxxj = 0;
      for (int j = 0; j <= k; ) {
        nx = x + dx[i] * j;
        ny = y + dy[i] * j;
        if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] == '.') {
          j += nxt[i][nx][ny];
          maxxj = j;
        } else {
          break;
        }
      }
      for (int j = 0; j <= k;) {
        nx = x + dx[i] * j;
        ny = y + dy[i] * j;
        if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] == '.') {
          if (vis[nx][ny] == -1) {
            vis[nx][ny] = w + 1;
            q.push({nx, ny});

            if (nx == x2 && ny == y2) {
              return w + 1;
            }
          }
          int cur = maxxj - j;
          j += nxt[i][nx][ny];
          nxt[i][nx][ny] = cur;
        } else {
          break;
        }
      }
   }
  }
  return -1;
}
int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  scanf("%d%d%d", &n, &m, &k);
  scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  x1--, y1--, x2--, y2--;

  s = vector<string>(n);
  vis = vector<vector<int>>(n, vector<int>(m, -1));
  nxt[0] = nxt[1] = nxt[2] = nxt[3] = vector<vector<int>>(n, vector<int>(m, 1));

  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  printf("%d\n", run());


#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Compiler output:
a.cc:25:9: error: 'int y1' redeclared as different kind of entity
   25 | int x1, y1, x2, y2;
      |         ^~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33,
                 from /usr/include/stdio.h:28,
                 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 run()':
a.cc:34:9: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(<brace-enclosed initializer list>)'
   34 |   q.push({x1, y1});
      |   ~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:8:
/usr/include/c++/14/bits/stl_queue.h:283:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, int>]'
  283 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:283:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::queue<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
  283 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:288:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, int>]'
  288 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:288:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::queue<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:35:11: error: invalid conversion from 'double (*)(double) noexcept' to 'std::vector<int>::size_type' {aka 'long unsigned int'} [-fpermissive]
   35 |   vis[x1][y1] = 0;
      |           ^~
      |           |
      |           double (*)(double) noexcept
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/queue:63:
/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: In function 'int main()':
a.cc:86:9: warning: ISO C++ forbids decrementing a pointer of type 'double (*)(double) noexcept' [-Wpointer-arith]
   86 |   x1--, y1--, x2--, y2--;
      |         ^~
a.cc:86:11: error: lvalue required as decrement operand
   86 |   x1--, y1--, x2--, y2--;
      |           ^~