Submission #554336

#TimeUsernameProblemLanguageResultExecution timeMemory
554336ian2024Rainforest Jumps (APIO21_jumps)C++14
0 / 100
4054 ms14920 KiB
#include <bits/stdc++.h> using namespace std; struct C_HASH { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); typedef pair<int, int> ii; typedef tuple<int, int, int> iii; typedef long long ll; const int INF = 1e9; const ll INFL = 1e18; const int MOD = 1000000007; #define SIZE(a) (int)(a).size() #define endl '\n' #define all(x) x.begin(), x.end() #define ALL(x) begin(x), end(x) int l[200005]; int r[200005]; #ifdef LOCAL_PROJECT void init(int N, std::vector<int> H); int minimum_jumps(int A, int B, int C, int D); int dfs(int a, int b); signed main() { int N, Q; assert(2 == scanf("%d %d", &N, &Q)); std::vector<int> H(N); for (int i = 0; i < N; ++i) { assert(1 == scanf("%d", &H[i])); } init(N, H); cerr << dfs(4, 6); for (int i = 0; i < Q; ++i) { int A, B, C, D; assert(4 == scanf("%d %d %d %d", &A, &B, &C, &D)); printf("%d\n", minimum_jumps(A, B, C, D)); } return 0; } #else #define cerr \ if (false) cerr #include "jumps.h" #endif void init(int N, std::vector<int> H) { fill(begin(l), end(l), -1); fill(begin(r), end(r), -1); set<int> s; vector<ii> v; for (int i = 0; i < N; ++i) { v.push_back({H[i], i}); } sort(all(v), greater<ii>()); for (int i = 0; i < N; ++i) { int height, idx; tie(height, idx) = v[i]; s.insert(idx); auto it = s.lower_bound(idx); if (it != s.begin()) { it--; l[idx] = *it; } it = s.upper_bound(idx); if (it != s.end()) { r[idx] = *it; } } } int dfs(int u, int target) { if (u == target) { return 0; } if (u == -1) { return INF; } return 1 + min(dfs(l[u], target), dfs(r[u], target)); } 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, dfs(i, j)); } } if (res == INF) return -1; return res; }
#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...