Submission #565555

#TimeUsernameProblemLanguageResultExecution timeMemory
565555MurotYRainforest Jumps (APIO21_jumps)C++14
21 / 100
288 ms16208 KiB
#include "jumps.h" #include <bits/stdc++.h> #define ll long long using namespace std; const int N=2*1e3+7; vector <int> a; vector <int> g[N]; bool u[N], u1[N]; int dp[N][N]; void init(int N, std::vector<int> H) { int n=N; a=H; vector <int> v; for (int i=n-1;i>=0;i--){ while (!v.empty() && a[i] > a[v.back()]) v.pop_back(); if (!v.empty()) g[i].push_back(v.back()); v.push_back(i); } v.clear(); for (int i=0;i<n;i++){ while (!v.empty() && a[i] > a[v.back()]) v.pop_back(); if (!v.empty()) g[i].push_back(v.back()); v.push_back(i); } for (int i=0;i<n;i++){ for (int j=0;j<n;j++) dp[i][j]=1e9; queue <int> q; q.push(i); dp[i][i]=0; while (!q.empty()){ int x1=q.front(); q.pop(); for (auto l:g[x1]){ if (dp[i][l] > dp[i][x1]+1){ dp[i][l]=dp[i][x1]+1; q.push(l); } } } } /* for (int i=0;i<n;i++){ for (int j=0;j<n;j++) cout << dp[i][j] <<" "; cout <<"\n"; }*/ } int minimum_jumps(int A, int B, int C, int D) { int ans=1e9; for (int i=A;i<=B;i++){ for (int j=C;j<=D;j++){ ans=min(ans, dp[i][j]); } } if (ans == 1e9) ans=-1; return ans; }
#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...