#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 1010;
char maze[maxn][maxn];
bool visited[2*maxn];
int dist[2*maxn], n, m;
vector<int>g[2*maxn];
int main() {
cin>>n>>m;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
cin>>maze[i][j];
if(maze[i][j] == '#') {
g[i].pb(j+n);
g[j+n].pb(i);
}
}
}
memset(dist,-1,sizeof(dist));
queue<int>q;
q.push(1);
dist[1] = 0;
while(!q.empty()) {
int curr = q.front();
q.pop();
for(int i:g[curr]) {
if(!visited[i]) {
dist[i] = dist[curr] + 1;
visited[i] = true;
q.push(i);
}
}
}
cout<<dist[n]<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |