Language: C++

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
string S[1000010];
bool visit[1000010] = {};
ll dist[1000010] = {};
typedef struct {
    ll x;
    ll y;
    ll d;
} P;


void solve(){
    ll H,W,K;
    cin >> H >> W >> K;
    ll x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--; y1--; x2--; y2--;
    rep(i,0,H) cin >> S[i];
    queue<P> que;
    que.push({x1,y1,0});
    ll dx[4] = {0,0,1,-1};
    ll dy[4] = {1,-1,0,0};
    bool reach = false;
    rep(i,0,H*W){
        dist[i] = INF;
    }

    while(not que.empty()){
        P l1 = que.front();
        que.pop();
        ll lx = l1.x, ly = l1.y;
        if(visit[lx * W + ly]) continue;
        visit[lx * W + ly] = true;
        if(lx == x2 && ly == y2){
            reach = true;
        }
        dist[lx*W+ly] = l1.d;

        rep(k,0,4){
            rep(d,1,K+1){
                ll xx = lx + dx[k] * d;
                ll yy = ly + dy[k] * d;
                if(xx >= 0 && xx < H && yy >= 0 && yy < W && visit[xx * W + yy] == false && S[xx][yy] == '.'){
                    que.push({xx,yy, l1.d+1});
                }else{
                    break;
                }
            }
        }
    }
    if(not reach){
        print(-1);
        return;
    }else{
        print(dist[x2*W+y2]);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:44:12: error: reference to 'visit' is ambiguous
   44 |         if(visit[lx * W + ly]) continue;
      |            ^~~~~
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:15:6: note:                 'bool visit [1000010]'
   15 | bool visit[1000010] = {};
      |      ^~~~~
a.cc:45:9: error: reference to 'visit' is ambiguous
   45 |         visit[lx * W + ly] = true;
      |         ^~~~~
/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:15:6: note:                 'bool visit [1000010]'
   15 | bool visit[1000010] = {};
      |      ^~~~~
a.cc:55:62: error: reference to 'visit' is ambiguous
   55 |                 if(xx >= 0 && xx < H && yy >= 0 && yy < W && visit[xx * W + yy] == false && S[xx][yy] == '.'){
      |                                                              ^~~~~
/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:15:6: note:                 'bool visit [1000010]'
   15 | bool visit[1000010] = {};
      |      ^~~~~