제출 #1054156

#제출 시각아이디문제언어결과실행 시간메모리
1054156Halym2007밀림 점프 (APIO21_jumps)C++17
37 / 100
4075 ms14140 KiB
#include <bits/stdc++.h> #include "jumps.h" using namespace std; #define ll long long #define sz size() #define ff first #define ss second #define pb push_back #define pii pair <int, int> const int N = 2e5 + 5; int n, dis[N]; vector <int> v[N]; bool vis[N]; bool tt = 0; void init(int N, vector<int> H) { n = N; stack <int> s; for (int i = 0; i < n; ++i) { if (H[i] != i + 1) { tt = 1; } while (!s.empty() and H[s.top()] <= H[i]) { s.pop(); } if (!s.empty()) { v[i].pb (s.top()); } s.push(i); } while (!s.empty()) s.pop(); for (int i = n - 1; i >= 0; i--) { while (!s.empty() and H[s.top()] <= H[i]) { s.pop(); } if (!s.empty()) { v[i].pb (s.top()); } s.push(i); } } int minimum_jumps(int A, int B, int C, int D) { if (!tt) return C - B; for (int i = 0; i < n; ++i) { vis[i] = 0; dis[i] = 1e9; } queue <int> q; for (int i = A; i <= B; ++i) { q.push(i); vis[i] = 1; dis[i] = 0; } while (!q.empty()) { int x = q.front(); q.pop(); for (int i : v[x]) { if (vis[i]) continue; q.push(i); dis[i] = dis[x] + 1; vis[i] = 1; if (i >= C and i <= D) { return dis[i]; } } } return -1; } //int main() { // freopen ("input.txt", "r", stdin); // int N, Q; // assert(2 == scanf("%d %d", &N, &Q)); // std::vector<int> H(N); // for (int i = 0; i < N; ++i) { // assert(1 == scanf("%d", &H[i])); // } // init(N, H); // // for (int i = 0; i < Q; ++i) { // int A, B, C, D; // assert(4 == scanf("%d %d %d %d", &A, &B, &C, &D)); // printf("%d\n", minimum_jumps(A, B, C, D)); // } // return 0; //}
#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...