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);
map<int, int> M;
vector<int> ys;
for (int i = 0; i < N; i++)
{
cin >> Tab[i];
ys.push_back(Tab[i]);
}
ys.push_back(deby);
ys.push_back(finy);
int buff = 0;
sort(ys.begin(), ys.end());
for (int i = 0; i < ys.size(); i++)
M[ys[i]] = buff++;
deby = M[deby];
finy = M[finy];
for (int i = 0; i < N; i++)
Tab[i] = M[Tab[i]];
vector<vector<int>> occ(N, vector<int>(N + 4));
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 - (ys[y] - ys[y - 1]), x, y - 1});
if (y < Tab[x])
PQ.push({t - (ys[y + 1] - ys[y]), 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])});
}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < ys.size(); i++)
| ~~^~~~~~~~~~~
# | 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... |