Language: C++

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define input(array) \
	repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int h, w, k;
	int ans = 0;
	cin >> h >> w >> k;
	Pi at, ter;
	cin >> at.F >> at.S >> ter.F >> ter.S;
	at.F--;
	at.S--;
	ter.F--;
	ter.S--;
	vector<string> c(h);
	input(c);
	VVi dis(h, Vi(w, INF));
	dis[at.F][at.S] = 0LL;
	queue<Pi> q;
	q.push(at);
	c[at.F][at.S] = '-';
	while (!q.empty()) {
		at = q.front();
		if (at == ter) {
			break;
		}
		q.pop();
		for (int ni = at.F + 1;
		     ni < min(h, k + 1 + at.F) and c[ni][at.S] != '@'; ni++) {
			if (c[ni][at.S] == '-') continue;
			if (chmin(dis[ni][at.S], 1 + dis[at.F][at.S])) {
				q.push(mp(ni, at.S));
				c[ni][at.S] = '-';
				if (ter.F == ni and ter.S = at.S) {
					goto fin;
				}
			} else {
				break;
			}
		}
		for (int nj = at.S + 1;
		     nj < min(w, k + 1 + at.S) and c[at.F][nj] != '@'; nj++) {
			if (c[at.F][nj] == '-') continue;
			if (chmin(dis[at.F][nj], 1 + dis[at.F][at.S])) {
				q.push(mp(at.F, nj));
				c[at.F][nj] = '-';
				if (ter.F == at.F and ter.S = nj) {
					goto fin;
				}
			} else {
				break;
			}
		}

		for (int ni = at.F - 1; ni >= max(0, at.F - k) and c[ni][at.S] != '@';
		     ni--) {
			if (c[ni][at.S] == '-') continue;
			if (chmin(dis[ni][at.S], 1 + dis[at.F][at.S])) {
				q.push(mp(ni, at.S));
				c[ni][at.S] = '-';
				if (ter.F == ni and ter.S = at.S) {
					goto fin;
				}
			} else {
				break;
			}
		}
		for (int nj = at.S - 1; nj >= max(0, at.S - k) and c[at.F][nj] != '@';
		     nj--) {
			if (c[at.F][nj] == '-') continue;
			if (chmin(dis[at.F][nj], 1 + dis[at.F][at.S])) {
				q.push(mp(at.F, nj));
				c[at.F][nj] = '-';
				if (ter.F == at.F and ter.S = nj) {
					goto fin;
				}
			} else {
				break;
			}
		}
	}
	fin:
	if (dis[ter.F][ter.S] == INF) {
		cout << -1 << endl;
	} else {
		cout << dis[ter.F][ter.S] << endl;
	}
	/*
	rep(i, h) {
	    rep(j, w) { clog << dis[i][j] << " "; }
	    clog << endl;
	}
	*/
}
/*

*/


Compiler output:
a.cc: In function 'int main()':
a.cc:76:49: error: lvalue required as left operand of assignment
   76 |                                 if (ter.F == ni and ter.S = at.S) {
      |                                                 ^
a.cc:89:51: error: lvalue required as left operand of assignment
   89 |                                 if (ter.F == at.F and ter.S = nj) {
      |                                                   ^
a.cc:103:49: error: lvalue required as left operand of assignment
  103 |                                 if (ter.F == ni and ter.S = at.S) {
      |                                                 ^
a.cc:116:51: error: lvalue required as left operand of assignment
  116 |                                 if (ter.F == at.F and ter.S = nj) {
      |                                                   ^