Submission #1052066

#TimeUsernameProblemLanguageResultExecution timeMemory
1052066user736482Rainforest Jumps (APIO21_jumps)C++17
37 / 100
4037 ms7104 KiB
#include<bits/stdc++.h> using namespace std; int lft[200007],rgt[200007]; bool czy1=1; bool odw[200007]; int n; void init(int N,vector<int>v){ n=N; stack<int>s; lft[200006]=200006; rgt[200006]=200006; //s.push(n); for(int i=0;i<n;i++){ lft[i]=200006; rgt[i]=200006; } //return; for(int i=0;i<n;i++){ if(s.empty() || v[s.top()]>v[i]) s.push(i); else{ rgt[s.top()]=i; s.pop(); i--; } } while(s.size()>0) s.pop(); for(int i=n-1;i>=0;i--){ if(s.empty() || v[s.top()]>v[i]) s.push(i); else{ czy1=0; lft[s.top()]=i; s.pop(); i++; } } //for(int i=0;i<n;i++) //cout<<lft[i]<<" "<<rgt[i]<<"\n"; } int minimum_jumps(int a,int b,int c,int d){ if(czy1) return c-b; odw[200006]=1; int ans[n]; for(int i=0;i<n;i++){ odw[i]=0; ans[i]=200007;} for(int i=a;i<=b;i++) odw[i]=1; priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq; for(int i=a;i<=b;i++){ pq.push({0,i}); } while(!pq.empty()){ pair<int,int>pom=pq.top(); pq.pop(); ans[pom.second]=pom.first; if(!odw[lft[pom.second]]){ odw[lft[pom.second]]=1; pq.push({pom.first+1,lft[pom.second]}); } if(!odw[rgt[pom.second]]){ odw[rgt[pom.second]]=1; pq.push({pom.first+1,rgt[pom.second]}); } //return 0; } int mn=200007; for(int i=c;i<=d;i++){ mn=min(mn,ans[i]); } if(mn==200007) mn=-1; //cout<<ans[11]; return mn; }
#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...