제출 #1101340

#제출 시각아이디문제언어결과실행 시간메모리
1101340Sunbae밀림 점프 (APIO21_jumps)C++17
4 / 100
847 ms15868 KiB
#include <bits/stdc++.h> #define z exit(0) using namespace std; const int MXN = 2e5 + 5; vector<int> g[MXN]; queue<int> q; int stk[MXN], nxt[2][MXN], d[MXN], n, sz; bool V(int i){ return 0 <= i && i < n;} int ch[2] = {1, 1}; void init(int N, vector<int> H){ n = N; int st = sz = 0, ed = n, del = 1; for(int j = 0; j<2; ++j){ int ff = 1; for(int i = st; i != ed; i += del){ if(!ff) ch[j] &= (H[i-del] <= H[i]); while(sz && H[stk[sz-1]] <= H[i]) --sz; if(sz) nxt[j][i] = stk[sz-1]; stk[sz++] = i; ff = 0; } st = n-1; ed = del = -1; sz = 0; } for(int j = 0; j<2; ++j){ for(int i = 0; i<n; ++i){ if(V(nxt[j][i])) g[i].push_back(nxt[j][i]); } } } int minimum_jumps(int A, int B, int C, int D){ if(ch[0] || ch[1]) return C - B; while(!q.empty()) q.pop(); fill(d, d+n, 1e8); for(int i = A; i<=B; ++i) d[i] = 0, q.emplace(i); while(!q.empty()){ int u = q.front(); q.pop(); for(int v: g[u]){ if(d[v] > d[u] + 1) d[v] = d[u] + 1, q.emplace(v); } } int mn = *min_element(d+C, d+D+1); if(mn >= 1e8) mn = -1; return mn; }
#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...