Submission #1114406

#TimeUsernameProblemLanguageResultExecution timeMemory
1114406lucascgarRainforest Jumps (APIO21_jumps)C++17
25 / 100
4051 ms5036 KiB
#include <bits/stdc++.h> using namespace std; /* se eu tenho um cara da esquerda sempre vale pegar primeiro cara que der da direita se eu tenho um destino na direita sempre vale pegar o maior cara da esquerda q chega la nenhuma subtituição nos intervalos muda nada pq */ typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long double, long double> pdd; const int MAXN = 2e5+10, MAXQ = 1e5+10, BIG = 1e9+8; int n, h[MAXN]; int r[MAXN], l[MAXN]; bool thing = 0; void init(int N, vector<int> H){ n = N; thing = 1; for (int i=0;i<n;i++){ h[i] = H[i]; if (h[i]!=i+1) thing=0; } if (thing) return; for (int i=0;i<n;i++){ r[i] = l[i] = -1; for (int j=i+1;j<n;j++) if (h[i]<h[j]){ r[i] = j; break; } for (int j=i-1;j>=0;j--) if (h[i]<h[j]){ l[i]=j; break; } } } int minimum_jumps(int A, int B, int C, int D){ // A <= B < C <= D if (thing){ return C-B; } int ans = BIG; vector<int> ds(n, -1); queue<int> q; for (int i=A;i<=B;i++){ q.push(i); ds[i]=0; } while (!q.empty()){ int u = q.front(); q.pop(); if (u>=C && u<=D){ ans = ds[u]; break; } if (l[u] != -1 && ds[l[u]]==-1){ ds[l[u]] = ds[u]+1; q.push(l[u]); } if (r[u] != -1 && ds[r[u]]==-1){ ds[r[u]] = ds[u]+1; q.push(r[u]); } } if (ans==BIG) return -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...