Language: C++

#include <bits/stdc++.h>
using namespace std;
const int maxn=1000005,dx[4]={-1,1,0,0},dy[4]={0,0,-1,1};
vector <int> No[maxn],sumx[maxn],sumy[maxn];
vector <char> mat[maxn];
struct edge { int obj,last; } e[maxn<<3];
int r,c,k,n,x1,y1,x2,y2,cnt,point[maxn],u[maxn],s[maxn];
bool vis[maxn];
void add_edge(int x,int y)
{
	cnt++;
	e[cnt].obj=y;
	e[cnt].last=point[x];
	point[x]=cnt;
}
void bfs()
{
	u[1]=No[x1][y1];
	vis[u[1]]=true;
	for (int head=1,tail=1;head<=tail;head++)
		for (int i=point[u[head]],v;i;i=e[i].last)
		{
			v=e[i].obj;
			if (!vis[v])
			{
				vis[v]=true;
				tail++;
				u[tail]=v;
				s[tail]=s[head]+1;
				if (v==No[x2][y2])
				{
					printf("%d\n",s[tail]);
					exit(0);
				}
			}
		}
}
int main()
{
	scanf("%d%d%d%d%d%d%d",&r,&c,&k,&x1,&y1,&x2,&y2);
	for (int i=1;i<=r;i++)
	{
		No[i].push_back(0);
		mat[i].push_back('.');
		for (int j=1;j<=c;j++)
		{
			char x;
			scanf(" %c",&x);
			No[i].push_back(++n);
			mat[i].push_back(x);
		}
	}
	for (int i=1;i<=r;i++)
	{
		sumx[i].push_back(0);
		for (int j=1;j<=c;j++)
			sumx[i].push_back(sumx[i][j-1]+(mat[i][j]=='@'));
	}
	for (int j=1;j<=c;j++)
	{
		sumy[j].push_back(0);
		for (int i=1;i<=r;i++)
			sumy[j].push_back(sumy[j][i-1]+(mat[i][j]=='@'));
	}
	for (int i=1;i<=r;i++)
		for (int j=1;j<=c;j++)
			if (mat[i][j]=='.')
				for (int d=0,x,y;d<4;d++)
				{
					x=i+dx[d];
					y=j+dy[d];
					if (x>=1 && x<=r && y>=1 && y<=c && mat[x][y]=='.')
						add_edge(No[i][j],No[x][y]);
					if (k==1) continue;
					x=i+dx[d]*k;
					y=j+dy[d]*k;
					if (x>=1 && x<=r && y>=1 && y<=c)
					{
						int tmp;
						if (x==i && j<y) tmp=sumx[x][y]-sumx[x][j-1]; else
						if (x==i && y<j) tmp=sumx[x][j]-sumx[x][y-1]; else
						if (i<x)
							tmp=sumy[y][x]-sumy[y][i-1]; else
							tmp=sumy[y][i]-sumy[y][x-1];
						if (!tmp) add_edge(No[i][j],No[x][y]);
					}
				}
	bfs();
	puts("-1");
	return 0;
}


Compiler output:
a.cc:7:16: error: 'int y1' redeclared as different kind of entity
    7 | int r,c,k,n,x1,y1,x2,y2,cnt,point[maxn],u[maxn],s[maxn];
      |                ^~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:33,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:257:1: note: previous declaration 'double y1(double)'
  257 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc: In function 'void bfs()':
a.cc:18:21: error: invalid conversion from 'double (*)(double) noexcept' to 'std::vector<int>::size_type' {aka 'long unsigned int'} [-fpermissive]
   18 |         u[1]=No[x1][y1];
      |                     ^~
      |                     |
      |                     double (*)(double) noexcept
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   initializing argument 1 of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = int; _Alloc = std::allocator<int>; reference = int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~