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 up(int x1, int y1, int x2, int y2){
return abs(x2 - x1) + abs (y2 - y1);
}
int arr[100000007];
int main(){
int n; cin >> n;
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
for(int i = 0; i < n; i++){
cin >> arr[i];
}
if(n == 1)cout << 0 <<endl;
else{
int res1 = up(x1,y1,x2,y2);
int res2 = 1e9;
if(x1 != n){
res2 = (arr[0] + 2) - y1 + up(x1 + 1, 1, x2, y2);
}
int res3 = 1e9;
if(x1 != 1)res3 = y1 + up(x1 - 1, arr[0] + 1, x2, y2);
else res3 = 1 + y1 + up(1, arr[0] + 1, x2, y2);
int res4 = n - x1;
res4 = res4 + 1 + min(up(n - 1, 1, x2, y2), up(n - 1, arr[0] + 1, x2, y2));
res1 = min(res1, res2);
res1 = min(res1, res3);
res1 = min(res1, res4);
cout << res1;
}
}
# | 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... |