This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int n, m, k, ans, arr[101010], mod=1e9+7;
vector<string> board(1010);
int sx, sy, ex, ey, dx[4]= {0, 0, 1, -1}, dy[4]= {1, -1, 0, 0};
void input()
{
int i, j;
cin>>n>>m;
for(i=0; i<n; i++)
cin>>board[i];
cin>>sx>>sy>>ex>>ey;
sx--;sy--;ex--;ey--;
}
bool valid(int x, int y)
{
return 0<=x&&x<n&&0<=y&&y<m;
}
int calc(vector<string> v, int x, int y, int d)
{
if(x==ex&&y==ey)
return 0;
if(d==0) return 1e9;
//cout<<"Calc at "<<x<<' '<<y<<'\n';
int i, j, ret=1e9, tx=x, ty=y;
v[tx][ty]='#';
for(i=0; i<4; i++)
{
x=tx;y=ty;
while(v[x+dx[i]][y+dy[i]]=='.')
{
x+=dx[i];
y+=dy[i];
}
if(x==tx&y==ty)
continue;
ret=min(ret, 1+calc(v, x, y, d-1));
}
//cout<<"Calc("<<x<<", "<<y<<") = "<<ret<<'\n';
return ret;
}
int main()
{
//freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
input();
int i, j, temp=0;
ans=calc(board, sx, sy, n*m);
if(ans==1e9) cout<<"-1";
else cout<<ans;
}
Compilation message (stderr)
skating.cpp: In function 'void input()':
skating.cpp:10:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
skating.cpp: In function 'int calc(std::vector<std::__cxx11::basic_string<char> >, int, int, int)':
skating.cpp:37:13: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
if(x==tx&y==ty)
~^~~~
skating.cpp:27:12: warning: unused variable 'j' [-Wunused-variable]
int i, j, ret=1e9, tx=x, ty=y;
^
skating.cpp: In function 'int main()':
skating.cpp:50:9: warning: unused variable 'i' [-Wunused-variable]
int i, j, temp=0;
^
skating.cpp:50:12: warning: unused variable 'j' [-Wunused-variable]
int i, j, temp=0;
^
skating.cpp:50:15: warning: unused variable 'temp' [-Wunused-variable]
int i, j, temp=0;
^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |