Submission #568295

#TimeUsernameProblemLanguageResultExecution timeMemory
568295drdilyorRainforest Jumps (APIO21_jumps)C++17
21 / 100
4030 ms51252 KiB
#if defined(ONPC) && !defined(_GLIBCXX_ASSERTIONS) #define _GLIBCXX_ASSERTIONS #endif #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> #include "jumps.h" #ifdef ONPC #include "t_debug.cpp" #else #define debug(...) 42 #endif #define allit(a) (a).begin(), (a).end() #define sz(a) ((int) (a).size()) using namespace std; using ll = long long; using vi = vector<int>; namespace pd = __gnu_pbds; template<typename K> using ordered_set = pd::tree<K, pd::null_type, less<int>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>; template<typename... T> using gp_hash_table = pd::gp_hash_table<T...>;//simple using statement gives warnings const int INF = 1e9; const ll INFL = 1e18; const int N = 2000; const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); mt19937 rng(RANDOM); vi h; vector<vi> adj; int memo[N][N]; int dis(int i, int j) { if (i == j) return 0; if (memo[i][j] != 0) return memo[i][j]; int res = INF; for (int e : adj[i]) { res = min(res, dis(e, j)); } return memo[i][j] = 1+res; } void init(int n, std::vector<int> h) { adj.resize(n); memset(memo, 0, sizeof(memo)); for (int i = 0; i < n; i++) { int j = i-1, k = i+1; for (; j >= 0; j--) { if (h[j] > h[i]) break; } for (; k < n; k++) { if (h[k] > h[i]) break; } if (j >= 0) adj[i].push_back(j); if (k < n) adj[i].push_back(k); } } int minimum_jumps(int A, int B, int C, int D) { int res = INF; for (int i = A; i <= B; i++) { for (int j = C; j <= D; j++) { res = min(res, dis(i, j)); } } return (res < INF ? res : -1); }
#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...