#include <bits/stdc++.h>
#define int long long
#define fir first
#define sec second
using namespace std;
int n;
int sr, sc, er, ec;
vector<int> l;
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin>>n;
cin>>sr>>sc>>er>>ec;
//s-row, s-col, e-row, e-col
l.resize(n+1);
for(int i=1; i<=n; i++){
cin>>l[i];
}
int len=l[1]+2;
int gh=sc+len-1-ec+abs(er-sr);
if(er<sr) gh--;
else gh++;
int b=abs(sr-er)+abs(sc-ec);
int c=len-1-sc+ec+abs(sr-er);
if(sr<er) c--;
else c++;
cout<<min(gh, min(b, c));
return 0;
return 0;
}
| # | 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... |