Submission #570065

#TimeUsernameProblemLanguageResultExecution timeMemory
570065Cyber_WolfRainforest Jumps (APIO21_jumps)C++14
0 / 100
4048 ms10684 KiB
#include "jumps.h" //#include "stub.cpp" #include <bits/stdc++.h> using namespace std; #define lg long long const lg sz = 2e5+5; vector<lg> adj[sz]; void init(int N, std::vector<int> H) { for(int i = 0; i < N; i++) { lg idx = i-1; while(idx >= 0) { if(H[idx] > H[i]) { adj[i].push_back(idx); break; } idx--; } idx = i+1; while(idx < N) { if(H[idx] > H[i]) { adj[i].push_back(idx); break; } idx++; } } } lg vis[sz], tmp; int minimum_jumps(int A, int B, int C, int D) { tmp++; lg ans = -1; queue<lg> q; for(int i = A; i <= B; i++) q.push(i), vis[i] = true; lg dist = 0; while(q.size() && ans == -1) { lg sz = q.size(); dist++; while(sz-- && ans == -1) { lg u = q.front(); q.pop(); for(auto it : adj[u]) { if(vis[it] == tmp) continue; if(it >= C && it <= D) { ans = dist; break; } vis[it] = tmp; q.push(it); } } } return C-B; }
#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...