제출 #981310

#제출 시각아이디문제언어결과실행 시간메모리
981310Faisal_Saqib밀림 점프 (APIO21_jumps)C++17
37 / 100
4022 ms25936 KiB
#include "jumps.h" #include <vector> #include <bits/stdc++.h> //#include "stub.cpp" using namespace std; const int N=2e5+2; int n; int dist[N]; vector<int> adj[N]; bool subtask1=0; 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); // cout<<"For "<<pp[j].second<<" edge with: "; if(it!=end(spl)) { // cout<<*it<<' '; adj[pp[j].second].push_back(*it); } if(it!=begin(spl)) { it--; // cout<<*it<<' '; adj[pp[j].second].push_back(*it); } // cout<<endl; 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)) { dist[dj]=dist[it.second]+1; pq.push({dist[dj],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...