제출 #1112801

#제출 시각아이디문제언어결과실행 시간메모리
1112801mariaclara밀림 점프 (APIO21_jumps)C++17
33 / 100
4062 ms5296 KiB
#include "jumps.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int MAXN = 2e5+5; #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define mk make_pair #define pb push_back #define fr first #define sc second int n, a[MAXN], l_max[MAXN], r_max[MAXN]; void init(int N, vector<int> H) { n = N; for(int i = 1; i <= N; i++) a[i] = H[i-1]; a[0] = a[N+1] = N+1; for(int i = 1; i <= N; i++) { l_max[i] = i-1; while(a[l_max[i]] < a[i]) l_max[i] = l_max[l_max[i]]; } for(int i = N; i >= 1; i--) { r_max[i] = i+1; while(a[r_max[i]] < a[i]) r_max[i] = r_max[r_max[i]]; } } int minimum_jumps(int A, int B, int C, int D) { A++; B++; C++; D++; queue<int> fila; vector<int> vis(n+2); vis[0] = vis[n+1] = 1; for(int i = A; i <= B; i++) fila.push(i), vis[i] = 1; int ans = n; while(!fila.empty()) { int x = fila.front(); fila.pop(); if(C <= x and x <= D) ans = min(ans, vis[x] - 1); if(!vis[l_max[x]]) vis[l_max[x]] = vis[x] + 1, fila.push(l_max[x]); if(!vis[r_max[x]]) vis[r_max[x]] = vis[x] + 1, fila.push(r_max[x]); } if(ans == n) return -1; return ans; }
#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...