Submission #1044083

#TimeUsernameProblemLanguageResultExecution timeMemory
1044083VahanAbrahamText editor (CEOI24_editor)C++14
14 / 100
126 ms22052 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; int xs, ys, xe, ye; cin >> n >> xs >> ys >> xe >> ye; for (int i = 1; i <= n; ++i) { cin >> l[i]; } queue<pair<int, int>> q; q.push({ xs,ys }); dist[xs][ys] = 0; while (q.empty() != 1) { pair<int, int> p; p = q.front(); q.pop(); for (int i = 0; i < 4; ++i) { int x = p.fr + dx[i], y = p.sc + dy[i]; if (x <= 0) { continue; } if (x > n) { continue; } if (x == p.fr) { if (y > l[x] + 1) { x++; y = 1; } else { if (y <= 0) { --x; y = l[x] + 1; } } } else { if (y > l[x] + 1) { y = l[x] + 1; } } if (x >= 1 && x <= n) { if (dist[x][y] == 0) { if (x == xs && y == ys) { continue; } dist[x][y] = dist[p.fr][p.sc] + 1; q.push({ x,y }); } } } } cout << dist[xe][ye] << 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...