이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |