#include <bits/stdc++.h>
#define FOR(i, a, b) for (auto i = (a); i <= (b); i++)
#define ROF(i, a, b) for (auto i = (a); i >= (b); i--)
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, sx, sy, tx, ty;
cin >> n >> sx >> sy >> tx >> ty;
sy--, ty--;
vector<int> a(n + 1);
FOR(i, 1, n) cin >> a[i];
int ans = 1e9;
if (sx == tx) {
if (sy < ty) ans = min(ty - sy, sy + a[1] - ty + 1);
else ans = min(sy - ty, a[1] - sy + ty + 1);
} else if (sx < tx) {
if (sy == ty) ans = 0;
else if (sy < ty) ans = min(ty - sy, sy + 1 + 1 + a[1] - ty);
else ans = min({sy - ty, a[1] - sy + 1 - 1 + ty, n - tx + n - tx + ty});
ans += tx - sx;
} else {
if (sy == ty) ans = 0;
else if (sy < ty) ans = min(ty - sy, sy + 1 - 1 + a[1] - ty);
else ans = min({ty - sy, a[1] - sy + 1 + 1 + ty, n - sx + n - sx + ty});
ans += sx - tx;
}
cout << ans << " ";
}
# | 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... |