#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
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;
^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3034 ms |
2644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3034 ms |
2644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3034 ms |
2644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |