이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |