Language: C++


#include<bits/stdc++.h>
#include <iostream>
#include<map>
#include <algorithm>
using namespace std;
typedef long long      ll;
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define cena           ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD  1000000007
#define maxn 500005
class myData
{
    public:
    int t;
    int x;
    int y;
    int d;
    myData(int t,int x,int y,int d)
    : t(t),x(x),y(y),d(d)
    {
    }
    bool operator<(const myData& a) const
    {
        return (this->t < a.t);
    }
};
ll exponentMod(ll A, ll B,ll C)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;
    ll y;
    if (B % 2 == 0) {
        y = exponentMod(A, B / 2, C);
        y = (y * y) % C;
    }
    else {
        y = A % C;
        y = (y * exponentMod(A, B - 1, C) % C) % C;
    }
    return (ll)((y + C) % C);
}
pair<int,int>  factorize(ll n) {
    int ans=1;
    int c=0;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            if(i!=2)
                ans*=i,c++;
            n/=i;
        }
    }
    if (n != 1) {
            if(n!=2)
        ans*=n,c++;
    }
    return {ans,c};
}
////////////    FENWICK TREE    //////////////////
map<ll,ll> bit;
int N1= 2e5;
void update(ll i){
    for(;i<=N1;i+=i&(-i))
        bit[i]++;
}
ll get(ll i){
    ll ans = 0;
    for(;i>0;i-=i&(-i))
        ans+=bit[i];
    return ans;
}
int now;
bool sortByVal(const myData &a,
               const myData &b)
{
    return (a.t<b.t);
}/*char s[1005][1005];
int vis[1005][1005];
//int a[15],b[15],c[15];
int n,m,p;
int check(int x,int y){
	if(x<1||x>n||y<1||y>m||s[x][y]=='#'||vis[x][y])return 0;
	return 1;
}struct node{
	int x,y;
};
int dx[10]={0,0,1,-1};
int dy[10]={1,-1,0,0};
queue<node>q[15];
void bfs(int k){
	node no,ne;
	int h=q[k].size();
	while(h--){
		no=q[k].front();
		q[k].pop();
		for(int i=0;i<4;i++){
			ne.x=no.x+dx[i];
			ne.y=no.y+dy[i];
			if(check(ne.x,ne.y)){
				vis[ne.x][ne.y]=1;
				q[k].push(ne);
				b[k]++;
			}
		}
	}
}*/

ll ans1=0;
/*ap<int,int>m;
int dfs(int i,int n) {
    m[i]=1;
    int j=2;
    while(abs(i*j)<=n){
            ans1+=j;
            if(m[i*j]==0)
            dfs(i*j,n);
            ans1+=j;
            if(m[-i*j]==0)
            dfs(-i*j,n);
            j++;
    }
}*/
#define MAXN   1000003
int spf[MAXN];
ll  calc[MAXN+1];
ll nCk(ll n,ll k,ll mod) {
    return ((((calc[n]%mod)*exponentMod(calc[k],mod-2,mod))%mod)*exponentMod(calc[n-k],mod-2,mod))%mod;
}
void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)
        spf[i] = i;
    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (int j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
set<int>getFactorization(int x)
{
    set<int> ret;
    while (x != 1)
    {
        ret.insert(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
bool prime[MAXN+1];
void sieve2()
{
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=MAXN; p++)
    {
        if (prime[p]==true)
        {
            for (int i=p*p; i<=MAXN; i += p)
                prime[i] = false;
        }
    }
}
int MEX(int a[],int n) {
    set<int>s;
    for(int i=0;i<n;i++) {
        s.insert(a[i]);
    }
    int c=0;
    for(auto i=s.begin();i!=s.end();i++) {
       if(*i==c) {
        c++;
       }
       else
        break;
    }
    return c;
}
int smallestDivisor(int n)
{
    if (n % 2 == 0)
        return 2;
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }
    return n;
}
char arr[1001][1001];
int visited[1001][1001];
int x1,y1,x2,y2,n,m;
int k_row[] = {-2,-1,0,1,2,-2,-1,1,2,-2,+2,-2,-1,+1,+2,-2,-1,0,+1,+2};
int k_col[] = {-2,-2,-2,-2,-2,-1,-1,-1,-1,0,0,+1,+1,+1,+1,2,2,2,2,2};
int k_row1[] = {0,0,-1,+1};
int k_col1[]= {-1,+1,0,0};
int cost[1001][1001];
bool isSafe(int i,int j) {
return (i<n && j<m && i>=0 && j>=0 && arr[i][j]=='.');}
int dfs(int i,int j,int c) {
    for(int p=0;p<4;p++) {
        if(isSafe(i+k_row1[p],j+k_col1[p])) {
            if(cost[i+k_row1[p]][j+k_col1[p]]>c)
            {
                 cost[i+k_row1[p]][j+k_col1[p]]=c;
                 dfs(i+k_row1[p],j+k_col1[p],c);
            }
        }
    }
    for(int p=0;p<20;p++) {
        if(isSafe(i+k_row[p],j+k_col[p])) {
            if(cost[i+k_row[p]][j+k_col[p]]>c+1)
            {
                 cost[i+k_row[p]][j+k_col[p]]=c+1;
                 dfs(i+k_row[p],j+k_col[p],c+1);
            }
        }
    }
}
int main() {
    cin>>n>>m;
    cin>>x1>>y1>>x2>>y2;
    for(int i=0;i<n;i++)
        for(int j=0;j<m;j++) cin>>arr[i][j];
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
        cost[i][j]=INT_MAX;
    cost[x1-1][y1-1]=0;
    dfs(x1-1,y1-1,0);
    if(cost[x2-1][y2-1]==INT_MAX)
        cout<<-1<<endl;
    else
        cout<<cost[x2-1][y2-1]<<endl;
     return 0;
}









Compiler output:
a.cc:203:8: error: 'int y1' redeclared as different kind of entity
  203 | int x1,y1,x2,y2,n,m;
      |        ^~
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:2:
/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 'int dfs(int, int, int)':
a.cc:230:1: warning: no return statement in function returning non-void [-Wreturn-type]
  230 | }
      | ^
a.cc: In function 'int main()':
a.cc:233:12: error: no match for 'operator>>' (operand types are 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} and 'double(double) noexcept')
  233 |     cin>>x1>>y1>>x2>>y2;
      |     ~~~~~~~^~~~
      |        |     |
      |        |     double(double) noexcept
      |        std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}
In file included from /usr/include/c++/14/sstream:40,
                 from /usr/include/c++/14/complex:45,
                 from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  170 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:170:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type 'double (*)(double) noexcept'
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
/usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  174 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:174:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'short int' [-fpermissive]
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
      |              |
      |              double (*)(double) noexcept
a.cc:233:14: error: cannot bind rvalue '(short int)y1' to 'short int&'
/usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  177 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:177:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'short unsigned int' [-fpermissive]
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
      |              |
      |              double (*)(double) noexcept
a.cc:233:14: error: cannot bind rvalue '(short unsigned int)y1' to 'short unsigned int&'
/usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
  181 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/14/istream:181:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
      |              |
      |              double (*)(double) noexcept
a.cc:233:14: error: cannot bind rvalue '(int)y1' to 'int&'
/usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  184 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:184:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'unsigned int' [-fpermissive]
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
      |              |
      |              double (*)(double) noexcept
a.cc:233:14: error: cannot bind rvalue '(unsigned int)y1' to 'unsigned int&'
/usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  188 |       operator>>(long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:188:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'long int' [-fpermissive]
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
      |              |
      |              double (*)(double) noexcept
a.cc:233:14: error: cannot bind rvalue '(long int)y1' to 'long int&'
/usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  192 |       operator>>(unsigned long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:192:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'long unsigned int' [-fpermissive]
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
      |              |
      |              double (*)(double) noexcept
a.cc:233:14: error: cannot bind rvalue '(long unsigned int)y1' to 'long unsigned int&'
/usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  199 |       operator>>(long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:199:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'long long int' [-fpermissive]
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
      |              |
      |              double (*)(double) noexcept
a.cc:233:14: error: cannot bind rvalue '(long long int)y1' to 'long long int&'
/usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  203 |       operator>>(unsigned long long& __n)
      |       ^~~~~~~~
/usr/include/c++/14/istream:203:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'long long unsigned int' [-fpermissive]
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
      |              |
      |              double (*)(double) noexcept
a.cc:233:14: error: cannot bind rvalue '(long long unsigned int)y1' to 'long long unsigned int&'
/usr/include/c++/14/istream:328:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  328 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/14/istream:328:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'void*' [-fpermissive]
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
      |              |
      |              double (*)(double) noexcept
a.cc:233:14: error: cannot bind rvalue '(void*)y1' to 'void*&'
/usr/include/c++/14/istream:122:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
  122 |       operator>>(__istream_type& (*__pf)(__istream_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:122:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'} [-fpermissive]
  233 |     cin>>x1>>y1>>x2>>y2;
      |              ^~
      |              |
      |              double (*)(double) noexcept
/usr/include/c++/14/istream:126:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>; __ios_type = std::basic_ios<char>]' (near match)
  126 |       operator>>(__ios_type& (*__pf)(__ios_type&))
      |       ^~~~~~~~
/usr/include/c++/14/istream:126:7: note:   conversion of argument 1 would be ill-formed:
a.cc:233:14: error: invalid conversion from 'double (*)(double) noexcept' to 'std::basic_istream<char>::__ios_type& (*)(std::basic_istream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}