Submission #1044336

#TimeUsernameProblemLanguageResultExecution timeMemory
1044336VahanAbrahamText editor (CEOI24_editor)C++17
0 / 100
1 ms2508 KiB
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <string> #include <algorithm> #include <cstring> #include <cstdio> #include <sstream> #include <map> #include <stack> #include <set> #include <queue> #include <list> #include <unordered_set> #include <unordered_map> #include <math.h> #include <bitset> #include <cmath> #include <vector> #include <iomanip> #include <random> #include <chrono> #include <cassert> using namespace std; #define ll long long #define fr first #define sc second #define pb push_back #define US freopen(".in", "r", stdin); freopen("j.out", "w", stdout); ll gcd(ll a, ll b) { if (a == 0 || b == 0) { return max(a, b); } if (a <= b) { return gcd(a, b % a); } else { return gcd(a % b, b); } } ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; } const int N = 300005; const ll oo = 100000000000000000, MOD = 1000000007; int l[N]; int dist[5005][5005]; int dx[4] = { 1,-1,0,0 }; int dy[4] = { 0,0,1,-1 }; void solve() { int n; ll xs, ys, xe, ye; cin >> n >> xs >> ys >> xe >> ye; for (int i = 1; i <= n; ++i) { cin >> l[i]; } if (xs == xe && ys == ye) { cout << 0 << endl; return; } ll ans = abs(xs - xe) + abs(ys - ye); if (xs == n) { cout << min(min(abs(xs - xe) + l[xe] + 1 - ye, abs(xs - xe) + ye - 1),ans) << endl; } else { if (xs == 1) { ans = min(ans, ys - 1 + xe - xs + ye - 1); ans = min(ans, l[xs] + 1 - ys + xe - xs + l[xe] + 1 - ye); cout << ans << endl; } else { if (xs > xe) { ans = min(ans, ys + xs - 1 - xe + l[xe] + 1 - ye); ans = min(ans, ys - 1 + xs - xe + ye - 1); ans = min(ans, l[xs] + 1 - ys + xs - xe + l[xe] + 1 - ye); ans = min(ans, l[xs] + 1 - ys + 1 + xs + 1 - xe + ye - 1); } else { ans = min(ans, ys + xe - (xs - 1) + l[xe] + 1 - ye); ans = min(ans, ys - 1 + xe - xs + ye - 1); ans = min(ans, l[xs] + 1 - ys + xe - xs + l[xe] + 1 - ye); ans = min(ans, l[xs] + 1 - ys + 1 + xe - (xs + 1) + ye - 1); } cout << ans << endl; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //US int tt = 1; //cin >> tt; while (tt--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...