Language: C++

// Standard Stuff
#include <bits/stdc++.h>
using namespace std;

// Macros
#define F  first
#define S  second
#define PB push_back
#define MP make_pair
#define ALL(container)   container.begin(),container.end()
#define RALL(container)  container.rbegin(),container.rend()
#define MAKE_UNIQUE(vec) vec.erase(unique(ALL(vec)),vec.end())

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = std::pair <int,int>;

// Random
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/* [a,b] */ template<class T> T rnd_IntType(T a, T b){ return uniform_int_distribution<T>(a, b)(rng); }
/* [a,b) */ template<class T> T rnd_RealType(T a, T b){ return uniform_real_distribution<T>(a,b)(rng); }

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m, y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// Helpers
vector<pii> moves_grid = { {0,1} , {0,-1} , {1,0} , {-1,0} };
// vec.assign() GOOD; vec.resize() BAD
// comparator, <

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const set<T> &v)    { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T,S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T,S> &v)  { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef VOID_d1097589d5c8e3676b0fd9e08281f3d4
	#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); d__f(_it, args); }
	void d__f(__attribute__((unused)) istream_iterator<string> it) {}
	template<typename Head, typename... Tail> void d__f(istream_iterator<string> it, Head H, Tail... T) { cerr << *it << " <=> [" << H << "]\n"; d__f(++it, T...); }
#else
	#define trace(args...)
#endif


class Thing{
public:

	int x, y, dist, p_x, p_y, dir;

	Thing(int _x, int _y, int _dist, int _p_x, int _p_y, int _dir)
	      : x(_x), y(_y), dist(_dist), p_x(_p_x), p_y(_p_y), dir(_dir)
	      {}

	bool operator < (Thing other) const {
		return dist > other.dist;
	}

	friend ostream& operator << (ostream &os, const Thing &t){
		os << "(" <<  t.x << "," << t.y << ") (" << t.p_x << "," << t.p_y << ")";
		os << " => " << t.dist << " " << t.dir;
		return os;
	}
};

void solve(){
	int h, w, k;
	cin >> h >> w >> k;

	pii from, to;
	cin >> from.F >> from.S >> to.F >> to.S;
	--from.F, --from.S, --to.F, --to.S;

	const int INF = (int)1e9;

	bool grid[h][w];
	int dist[h][w];
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			char ch; cin >> ch;
			grid[i][j] = ch == '.';
			dist[i][j] = INF;
		}
	}

	priority_queue<Thing, vector<Thing>> q;
	dist[from.F][from.S] = 0;

	for(int m = 0; m < 4; ++m){
		int nx = from.F + moves_grid[m].F, ny = from.S + moves_grid[m].S;
		if(0 <= nx and nx < h and 0 <= ny and ny < w and grid[nx][ny]){
			q.push(Thing{nx, ny, 1, from.F, from.S, m});
			dist[nx][ny] = 1;
		}
	}	

	while(not q.empty() and dist[to.F][to.S] == INF){
		auto curr = q.top(); q.pop();
		int x = curr.x, y = curr.y;

		if(dist[x][y] < curr.d) continue;

		for(int m = 0; m < 4; ++m){
			int nx = x + moves_grid[m].F, ny = y + moves_grid[m].S;
			if(0 <= nx and nx < h and 0 <= ny and ny < w){
				if(not grid[nx][ny]) continue;
				trace(curr,nx,ny);
				int p_x = curr.dir == m ? curr.p_x : x;
				int p_y = curr.dir == m ? curr.p_y : y;
				int d = dist[p_x][p_y] + (abs(nx - p_x) + abs(ny - p_y) + k - 1) / k;
				if(dist[nx][ny] < d) continue;
				dist[nx][ny] = d;
				q.push(Thing{nx, ny, d, p_x, p_y, m});
			}
		}
	}

	cout << (dist[to.F][to.S] == INF ? -1 : dist[to.F][to.S]) << "\n";
}

signed main (void){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int tt = 1;
	// cin >> tt;
	while(tt--) solve();
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:105:38: error: 'class Thing' has no member named 'd'
  105 |                 if(dist[x][y] < curr.d) continue;
      |                                      ^