Submission #1101300

#TimeUsernameProblemLanguageResultExecution timeMemory
1101300SunbaeRainforest Jumps (APIO21_jumps)C++17
33 / 100
4014 ms15972 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;} void init(int N, vector<int> H){ n = N; int st = sz = 0, ed = n, del = 1; for(int j = 0; j<2; ++j){ for(int i = st; i != ed; i += del){ while(sz && H[stk[sz-1]] <= H[i]) --sz; if(sz) nxt[j][i] = stk[sz-1]; stk[sz++] = i; } 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){ 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...