제출 #478185

#제출 시각아이디문제언어결과실행 시간메모리
478185khoabright밀림 점프 (APIO21_jumps)C++17
25 / 100
4034 ms5016 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pii pair<int, int> #define all(x) x.begin(), x.end() #define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i) #define rep1(i, a, b) for (int i = (int)a; i >= (int)b; --i) #define mp make_pair const int N = 2e5 + 5; int L[N], R[N], h[N]; int my_size; bool sub1 = 1; void cal_LR() { rep(i, 1, my_size) if (h[i] != i) {sub1 = 0; break;} if (sub1) return; rep(i, 1, my_size) { rep1(j, i - 1, 1) if (h[j] > h[i]) { L[i] = j; break; } rep(j, i + 1, my_size) if (h[j] > h[i]) { R[i] = j; break; } } } int minimum_jumps(int a, int b, int c, int d) { if (sub1) return c - b; ++a, ++b, ++c, ++d; queue<pii> q; vector<bool> vst(my_size + 1); vst[0] = 1; rep(i, a, b) q.push({i, 0}), vst[i] = 1; while (!q.empty()) { auto [u, w] = q.front(); q.pop(); if (c <= u && u <= d) return w; int v = L[u]; if (!vst[v]) { q.push({v, w + 1}); vst[v] = 1; } v = R[u]; if (!vst[v]) { q.push({v, w + 1}); vst[v] = 1; } } return -1; } void init(int sz, vector<int> array) { my_size = sz; rep(i, 1, my_size) h[i] = array[i - 1]; cal_LR(); } // int main() { // ios_base::sync_with_stdio(0); // cin.tie(0); cout.tie(0); // // int x; cin >> x; // // int array[10]; // // rep(i, 1, x) cin >> array[i - 1]; // // init(x,array); // // rep(i, 1, my_size) cout << h[i] << ' '; // // cout << '\my_size'; // // rep(i, 1, my_size) cout << L[i] << ' ' << R[i]<< '\my_size'; // // int q; cin >> q; // // while (q--) { // // int A, B, C, D; // // cin >> A >> B >> C >> D; // // cout << minimum_jumps(A + 1, B + 1, C + 1, D + 1) << '\my_size'; // // } // }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...