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;
int main()
{
int N;
cin >> N;
int debx, deby, finx, finy;
cin >> debx >> deby >> finx >> finy;
debx--, deby--, finx--, finy--;
vector<int> Tab(N);
for (int i = 0; i < N; i++)
cin >> Tab[i];
vector<vector<int>> occ(N, vector<int>(5001));
priority_queue<vector<int>> PQ;
PQ.push({0, debx, deby});
while (!PQ.empty())
{
int x = PQ.top()[1], y = PQ.top()[2], t = PQ.top()[0];
PQ.pop();
if (occ[x][y])
continue;
occ[x][y] = 1;
if (x == finx && y == finy)
{
cout << -t;
return 0;
}
if (y > 0)
PQ.push({t - 1, x, y - 1});
if (y < Tab[x])
PQ.push({t - 1, x, y + 1});
if (x > 0 && y == 0)
PQ.push({t - 1, x - 1, Tab[x - 1]});
if (x < N - 1 && y == Tab[x])
PQ.push({t - 1, x + 1, 0});
if (x < N - 1)
PQ.push({t - 1, x + 1, min(y, Tab[x + 1])});
if (x > 0)
PQ.push({t - 1, x - 1, min(y, Tab[x - 1])});
}
}
# | 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... |