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>
#define div /
#define ll long long
#define fore(i, l, r) for(int i=int(l); i<int(r); i++)
#define sz(a) int((a).size())
using namespace std;
const int INF = 1e9;
const int MX = 5e5 + 23;
const int MOD = 1000000007;
const int MAX_N = 5e5+23;
const int N = 1e6;
void solve() {
int n; cin >> n;
int sl,sc,el,ec;
cin >> sl >> sc >> el >> ec;
int l[n];
fore(i,0,n)
cin >> l[i];
int ans = abs(sl-el) + abs(sc-ec);
if(sl == 1)
ans = min(ans,abs(2-el)+abs(1-ec)+1);
if(sl == 2) {
ans = min(ans,abs(1-el)+abs(l[0]-ec)+1);
} else
ans=min(ans,abs(1-el)+abs(l[0]-ec)+2);
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
int t=1;
while(t--) solve();
}
# | 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... |