Submission #981385

#TimeUsernameProblemLanguageResultExecution timeMemory
981385Faisal_SaqibRainforest Jumps (APIO21_jumps)C++17
37 / 100
4054 ms25784 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; const int N=2e5+2; int dist[N],n,subtask1; vector<int> adj[N]; void init(int NP, std::vector<int> h) { subtask1=is_sorted(begin(h),end(h)); n=NP; set<int> spl; vector<pair<int,int>> pp; for(int j=0;j<n;j++) pp.push_back({h[j],j}); sort(begin(pp),end(pp)); for(int j=n-1;j>=0;j--) { auto it = spl.upper_bound(pp[j].second); if(it!=end(spl)) adj[pp[j].second].push_back(*it); if(it!=begin(spl)) adj[pp[j].second].push_back(*(--it)); spl.insert(pp[j].second); } } int minimum_jumps(int a, int b, int c, int d) { if(subtask1) return max(0,c-b); for(int j=0;j<=n;j++) dist[j]=2e9; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq; for(int st=a;st<=b;st++) pq.push({dist[st]=0,st}); while(pq.size()) { auto it=pq.top(); if(c<=it.second and it.second<=d) return it.first; pq.pop(); if(dist[it.second]==it.first) for(auto dj:adj[it.second]) if(dist[dj]>(dist[it.second]+1)) pq.push({dist[dj]=dist[it.second]+1,dj}); } return -1; }
#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...