제출 #587755

#제출 시각아이디문제언어결과실행 시간메모리
587755M_W밀림 점프 (APIO21_jumps)C++17
37 / 100
4058 ms14400 KiB
#include <bits/stdc++.h> using namespace std; int dist[200002]; int l[200002], r[200002]; vector<pair<int, int>> v; int N; bool st1 = true; void init(int N_tmp, vector<int> H) { N = N_tmp; for(int i = 0; i < N; i++){ v.push_back({H[i], i + 1}); if(H[i] != i + 1) st1 = false; } sort(v.begin(), v.end(), greater<pair<int, int>>()); set<pair<int, int>> v2; for(auto [x, tmp] : v){ if(v2.empty()){ v2.insert({tmp, x}); continue; } auto it = v2.lower_bound({tmp, 0}); // printf(">> %d %d : %d %d\n", x, tmp, (*it).first, (*it).second); if(it != v2.end()) r[x] = (*it).second; if(it != v2.begin()){ it--; l[x] = (*it).second; } v2.insert({tmp, x}); } } int minimum_jumps(int A, int B, int C, int D) { if(st1) return C - B; int ans = 1000000000; A++; B++; C++; D++; for(int i = 0; i <= N; i++) dist[i] = 1000000000; for(auto [x, idx]: v){ if(idx >= C && idx <= D) dist[x] = 0; if(idx >= A && idx <= B) ans = min({ans, dist[l[x]] + 1, dist[r[x]] + 1}); dist[x] = min({dist[x], dist[l[x]] + 1, dist[r[x]] + 1}); // printf(">> %d (%d, %d) : %d %d\n", x, l[x], r[x], dist[l[x]], dist[r[x]]); } return ans == 1000000000 ? -1 : 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...