Submission #1234382

#TimeUsernameProblemLanguageResultExecution timeMemory
1234382CELD_07Rainforest Jumps (APIO21_jumps)C++20
0 / 100
4050 ms7796 KiB
#include "jumps.h" #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> typedef long long ll; typedef long double ld; #define endl "\n" #define vll vector<ll> #define sd second #define ft first #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() #define pll pair<ll, ll> #define mod 1000000007 #define _set tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> #define inf (ll)1e15 #define db(x) cout<<#x<<" : "<<x<<endl; #define PRESICION(x) cout.setf(ios::fixed,ios::floatfield); cout.precision(x); using namespace std; using namespace __gnu_pbds; ll dx[]={1, -1, 0, 0}; ll dy[]={0, 0, 1, -1}; inline ll sm(ll a, ll b){ return ((a%mod)+(b%mod))%mod; } inline ll ml(ll a, ll b){ return ((a%mod)*(b%mod))%mod; } inline ll rs(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod; } ll bpow(ll a , ll b) { if (b==0)return 1; if (b%2!=0)return ((bpow(a, b-1)%mod)*(a%mod))%mod; ll r=bpow (a ,b/ 2) ; return ((r%mod)*(r%mod))%mod; } vector<ll> v, v1, v2; void init(int N, vector<int> H) { vector<ll>().swap(v); vector<ll>().swap(v1); vector<ll>().swap(v2); stack<pair<ll, ll>> s; v.assign(N, -1); v1.assign(N, -1); for(int i=0; i<N; i++)v2.push_back(H[i]); for(int i=N-1; i>=0; i--){ while(!s.empty() && s.top().ft<H[i])s.pop(); if(!s.empty())v[i]=s.top().sd; s.push({H[i], i}); } stack<pair<ll, ll>>().swap(s); for(int i=0; i<N; i++){ while(!s.empty() && s.top().ft<H[i])s.pop(); if(!s.empty())v1[i]=s.top().sd; s.push({H[i], i}); } //for(int i=0; i<N; i++)cout<<i<<" "<<v[i]<<" "<<v1[i]<<endl; } int minimum_jumps(int A, int B, int C, int D) { ll res=LLONG_MAX; for(int i=A; i<=B; i++){ for(int j=C; j<=D; j++){ ll o=i; ll cnt=0; while(o!=j && max(v[o], v1[o])>-1){ if(v[o]==-1)o=v1[o]; else if(v1[o]==-1)o=v[o]; else { ll o1=v[o], o2=v1[o]; if(max(v2[o1], v2[o2])==v2[o2])swap(o2, o1); if(v2[o1]<v2[j])o=o1; else o=o2; } cnt++; } if(o==j)res=min(res, cnt); } } return (res==LLONG_MAX ? -1 : res); }/* int main(){ init(7, {3, 2, 1, 6, 4, 5, 7}); cout<<minimum_jumps(0, 1, 2, 2)<<endl; } */
#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...