제출 #1044906

#제출 시각아이디문제언어결과실행 시간메모리
1044906alex_2008Text editor (CEOI24_editor)C++14
56 / 100
4053 ms267028 KiB
#include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <map> #include <queue> #include <stack> #include <set> typedef long long ll; using namespace std; const int N = 1e6 + 10; int l[N]; set <int> ms; priority_queue <pair<int, pair<int, int>>> Q; map <pair<int, int>, int> mp; void check(pair<int, int> v, int d) { if (mp.find(v) == mp.end() || mp[v] > d) { mp[v] = d; Q.push({ -d, v }); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int sl, sc, el, ec; cin >> sl >> sc >> el >> ec; ms.insert(1); ms.insert(sc); ms.insert(ec); for (int i = 1; i <= n; i++) { cin >> l[i]; l[i]++; ms.insert(l[i]); } mp[{ sl, sc }] = 0; Q.push({ 0, { sl, sc } }); while (!Q.empty()) { pair<int, pair<int, int>> v = Q.top(); Q.pop(); //cout << v.first << " " << v.second.first << " " << v.second.second << "\n"; ll d = -v.first; int r = v.second.first; int c = v.second.second; if (mp[{ r, c }] != d) continue; if (c == l[r]) { if (r != n) { check({ r + 1, 1 }, d + 1); } } else { auto it = ms.upper_bound(c); check({ r, *it }, *it - c + d); } if (c == 1) { if (r != 1) { check({ r - 1, l[r - 1] }, d + 1); } } else { auto it = ms.lower_bound(c); it--; check({ r, *it }, c - *it + d); } if (r > 1) { check({ r - 1, min(l[r - 1], c) }, d + 1); } if (r < n) { check({ r + 1, min(l[r + 1], c) }, d + 1); } } cout << mp[{ el, ec }] << "\n"; }
#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...