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;
typedef int ll; // ! CAREFUL
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef pair<int, int> pi;
typedef vector<bool> vb;
#define fi first
#define se second
#define IOS cin.tie(nullptr); cout.tie(nullptr); ios_base::sync_with_stdio(false)
#define pb push_back
ll solve(ll n, ll sl, ll sc, ll el, ll ec, const vll& l) {
if(sl == 1 && el == 0) {
return min(ec + 1, l[0] - ec);
} else if(sl == 1 && el == 1) {
return 0;
} else if(el == 1) {
return 1;
} else {
return min(ec + 2, min(l[0] - ec - 1 + 2, abs(ec - sc)));
}
}
int main() {
IOS;
ll n;
cin >> n;
ll sl, sc;
ll el, ec;
cin >> sl >> sc;
cin >> el >> ec;
sl--; sc--;
el--; ec--;
vll l(n, 0);
for(ll& lv : l) {
cin >> lv;
lv++; // ! WARNING, already added one
}
cout << solve(n, sl, sc, el, ec, l) << endl;
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... |