이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
const ll INF = 100000000000000000;
int main(){
ll n;
cin >> n;
vector<ll> arr(n);
ll a,b;
ll x,y;
cin >> a >> b >> x >> y;
a--;b--;x--;y--;
FOR(i,0,n) cin >> arr[i];
ll ans = INF;
ans = abs(a-x) + abs(b-y);
if (a != n-1) ans = min(ans, abs(b-arr[a]) + 1 + abs(0-y) + abs((a+1)-x));
if (a != 0) ans = min(ans, abs(b) + 1 + abs(arr[x]-y) + abs((a-1)-x));
ans = min(ans, abs((n-1)-a) + abs((n-1) - x) + abs(0-y));
cout << ans << endl;
}
# | 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... |