Language: C++

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>
 
using namespace std;
using namespace __gnu_pbds;
 
#define endl '\n'
 
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template<typename T>
static T randint(T lo, T hi){
	return uniform_int_distribution<T>(lo, hi)(rng);
}

struct data{

	int f, c, cost;

	data(int f, int c, int cost) : f(f), c(c), cost(cost){ }

	bool operator<(const data o)const{
		return cost > o.cost;
	}

};

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n, m, k;
	cin >> n >> m >> k;

	int xo, yo, xi, yi;
	

	vector<vector<char>> a(n + 1, vector<char>(m + 1));
	vector<set<int>> row(n + 1), col(m + 1);
	vector<set<int>> r_block(n + 1), c_block(m + 1);
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++){
			cin >> a[i][j];
			if(a[i][j] == '@'){
				r_block[i].insert(j);
				c_block[j].insert(i);
				continue;
			}

			row[i].insert(j);
			col[j].insert(i);
		}

	cin >> xo >> yo >> xi >> yi;

	priority_queue<data> pq;
	pq.push(data(xo, yo, 0));

	row[xo].erase(yo);
	col[yo].erase(xo);

	while(!pq.empty()){
		auto u = pq.top();pq.pop();
		int x = u.f, y = u.c, cost = u.cost;

		if(x == xi && y == yi){
			cout << cost << endl;
			return 0;
		}

		auto lo = r_block[x].lower_bound(y);
		auto hi = r_block[x].upper_bound(y);

		int b, e;

		if(lo == r_block[x].begin())
			b = 0;
		else{
			lo--;
			b = *lo;
		}

		if(hi == r_block[x].end())
			e = m + 1;
		else
			e = *hi;

		lo = row[x].lower_bound(max(b + 1, y - k));
		hi = row[x].upper_bound(min(e - 1, y + k));

		while(lo != hi){
			pq.push(data(x, *lo, cost + 1));
			lo++;
		}

		row[x].erase(row[x].lower_bound(max(b + 1, y - k)), hi);

		lo = c_block[y].lower_bound(x);
		hi = c_block[y].upper_bound(x);

		if(lo == c_block[y].begin())
			b = 0;
		else{
			lo--;
			b = *lo;
		}

		if(hi == c_block[y].end())
			e = n + 1;
		else
			e = *hi;

		lo = col[y].lower_bound(max(b + 1, x - k));
		hi = col[y].upper_bound(min(e - 1, x + k));

		while(lo != hi){
			pq.push(data(*lo, y, cost + 1));
			lo++;
		}

		col[y].erase(col[y].lower_bound(max(b + 1, x - k)), hi);

	}

	cout << -1 << endl;


	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:65:28: error: template argument 1 is invalid
   65 |         priority_queue<data> pq;
      |                            ^
a.cc:65:28: error: template argument 2 is invalid
a.cc:65:28: error: template argument 3 is invalid
a.cc:66:12: error: request for member 'push' in 'pq', which is of non-class type 'int'
   66 |         pq.push(data(xo, yo, 0));
      |            ^~~~
a.cc:66:17: error: reference to 'data' is ambiguous
   66 |         pq.push(data(xo, yo, 0));
      |                 ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data{
      |        ^~~~
a.cc:71:19: error: request for member 'empty' in 'pq', which is of non-class type 'int'
   71 |         while(!pq.empty()){
      |                   ^~~~~
a.cc:72:29: error: request for member 'top' in 'pq', which is of non-class type 'int'
   72 |                 auto u = pq.top();pq.pop();
      |                             ^~~
a.cc:72:38: error: request for member 'pop' in 'pq', which is of non-class type 'int'
   72 |                 auto u = pq.top();pq.pop();
      |                                      ^~~
a.cc:75:31: error: 'y' was not declared in this scope
   75 |                 if(x == xi && y == yi){
      |                               ^
a.cc:76:33: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   76 |                         cout << cost << endl;
      |                                 ^~~~
      |                                 cosl
a.cc:80:50: error: 'y' was not declared in this scope
   80 |                 auto lo = r_block[x].lower_bound(y);
      |                                                  ^
a.cc:101:28: error: request for member 'push' in 'pq', which is of non-class type 'int'
  101 |                         pq.push(data(x, *lo, cost + 1));
      |                            ^~~~
a.cc:101:33: error: reference to 'data' is ambiguous
  101 |                         pq.push(data(x, *lo, cost + 1));
      |                                 ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data{
      |        ^~~~
a.cc:101:46: error: 'cost' was not declared in this scope; did you mean 'cosl'?
  101 |                         pq.push(data(x, *lo, cost + 1));
      |                                              ^~~~
      |                                              cosl
a.cc:126:28: error: request for member 'push' in 'pq', which is of non-class type 'int'
  126 |                         pq.push(data(*lo, y, cost + 1));
      |                            ^~~~
a.cc:126:33: error: reference to 'data' is ambiguous
  126 |                         pq.push(data(*lo, y, cost + 1));
      |                                 ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:22:8: note:                 'struct data'
   22 | struct data{
      |        ^~~~
a.cc:126:46: error: 'cost' was not declared in this scope; did you mean 'cosl'?
  126 |                         pq.push(data(*lo, y, cost + 1));
      |                                              ^~~~
      |                                              cosl