Language: C++


#include<bits/stdc++.h>

using namespace std;

#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back
#define  mp             make_pair
#define  s              second
#define  f              first
#define  dline          cerr<<"///REACHED///\n";
#define  deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   N  =  1e+6+7;

vll adj[N];
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

//<<-----Declare Variable Here------->>//
int t=1;
ll n,m,k;
ll x1,g1,x2,g2;
string s[N];
ll ans = 1e+18;
ll visit[N],visit_act[N];
struct Point{
	ll x,y,res;
};
//<<-----Implement Functions Here---->>//
void bfs()
{
	visit[(x1-1)*m+g1] = 1;
	queue<Point>q;
	q.push({x1,g1,0});

	while(!q.empty())
	{
		Point p = q.front();q.pop();
		ll x = p.x;ll y = p.y;ll res = p.res;

		visit_act[(x-1)*m+y] = 1;
		if(x==x2&&y==g2)
		{
			ans =min(ans,res);
			break;
		}
		
		for(ll i=0;i<4;i++)
		{
			for(ll j=1;j<=k;j++)
			{
				ll dx = x+j*dx4[i];
				ll dy = y+j*dy4[i];
				if(visit_act[(dx-1)*m+dy]==1||s[dx][dy]=='@')break;
				if(visit[(dx-1)*m+dy]==0)
				{
					q.push({dx,dy,res+1});
					visit[(dx-1)*m+dy]=1;
				}
			}
		}

	}
}
//<<-----Start of Main--------------->>//
void MAIN(){
		cin>>n>>m>>k;
		cin>>x1>>g1>>x2>>g2;

		for(ll i=1;i<=n;i++)
		{
			cin>>s[i];
			s[i] = '@' + s[i] + '@';
		}
		s[0] = s[n+1] = string(m+2,'@');
		bfs();
		if(ans==1e+18)cout<<-1;
		else cout<<ans;

		
}

int main(){
	fastio;randomINIT;

	//cin>>t;
	while(t--){
		MAIN();
	}

   
}

Compiler output:
a.cc: In function 'void bfs()':
a.cc:51:9: error: reference to 'visit' is ambiguous
   51 |         visit[(x1-1)*m+g1] = 1;
      |         ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:2:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:44:4: note:                 'll visit [1000007]'
   44 | ll visit[N],visit_act[N];
      |    ^~~~~
a.cc:74:36: error: reference to 'visit' is ambiguous
   74 |                                 if(visit[(dx-1)*m+dy]==0)
      |                                    ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:44:4: note:                 'll visit [1000007]'
   44 | ll visit[N],visit_act[N];
      |    ^~~~~
a.cc:77:41: error: reference to 'visit' is ambiguous
   77 |                                         visit[(dx-1)*m+dy]=1;
      |                                         ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:44:4: note:                 'll visit [1000007]'
   44 | ll visit[N],visit_act[N];
      |    ^~~~~