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;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll R,C,N;
cin>>R>>C>>N;
pair<ll,ll> start, end;
cin>>start.first>>start.second;
cin>>end.first>>end.second;
start.first--, start.second--, end.first--, end.second--;
char arr[R][C];
for(ll i = 0;i < R;i++){
for(ll j = 0;j < C;j++){
cin>>arr[i][j];
}
}
deque<pair<ll,ll> > dq;
ll dist[R][C];
bool visited[R][C];
memset(dist,0,sizeof(dist));
memset(visited,0,sizeof(visited));
int Hy[] = {0,0,-1,1};
int Wx[] = {-1,1,0,0};
dq.push_back({start.first,start.second});
dist[start.first][start.second] = 0;
visited[start.first][start.second] = 1;
while(!dq.empty()){
ll y = dq.front().first;
ll x = dq.front().second;
dq.pop_front();
visited[y][x] = 1;
for(ll i = 0;i < 4;i++){
ll a = y + Hy[i];
ll b = x + Wx[i];
if(a < 0 || a >= R || b < 0 || b >= C || visited[a][b]) continue;
if(arr[a][b] == '#'){
dq.push_back({a,b});
dist[a][b] = dist[y][x] + 1;
visited[a][b] = 1;
}else{
dq.push_front({a,b});
dist[a][b] = dist[y][x];
visited[a][b] = 1;
}
}
}
cout<<dist[end.first][end.second]<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |