Submission #1047502

#TimeUsernameProblemLanguageResultExecution timeMemory
1047502Marco_EscandonRainforest Jumps (APIO21_jumps)C++11
4 / 100
695 ms94772 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; ll n; vector<vector<ll>>PD,PI; vector<vector<ll>> cad; vector<ll> vD; void dfs(ll node, ll d) { vD[node]=d; for(auto i:cad[node]) dfs(i,d+1); } void init(int N, std::vector<int> h) { n=N; stack<ll> q; PD.assign(24,vector<ll>(n+6,n+5)); PI.assign(24,vector<ll>(n+6,-1)); cad.resize(n+6);vD.resize(n+6); for(int i=0; i<n; i++) { while(!q.empty()&&h[i]>h[q.top()]) { PD[0][q.top()]=i; q.pop(); } if(!q.empty()) PI[0][i]=q.top(); q.push(i); } for(int i=0; i<n; i++) cad[PD[0][i]].push_back(i); for(int i=1; i<24; i++) for(int j=0; j<n+6; j++) PD[i][j]=PD[i-1][PD[i-1][j]]; dfs(n+5,0); } ll sol(ll node, ll a, ll b) { ll c=0; for(int i=23; i>-1; i--) { if(vD[PD[i][node]]>vD[a]) { c+=(1<<i); node=PD[i][node]; } } node=PD[0][node]; if(node>b) return 1e9; return c+1; } int minimum_jumps(int A, int B, int C, int D) { ll c1=0; ll p=B; ll bs=1e9; while(p!=-1) { bs=min(bs,c1+sol(p,C,D)); p=PI[0][p]; if(p<A) c1++; } if(bs==1e9) bs=-1; return bs; }
#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...