Submission #728043

#TimeUsernameProblemLanguageResultExecution timeMemory
728043grossly_overconfidentRainforest Jumps (APIO21_jumps)C++17
0 / 100
4019 ms1048576 KiB
//#include "jumps.h" #include <bits/stdc++.h> using namespace std; #define endl '\n' //#define int long long vector<vector<int>> adj; void init(int n, vector<int> H){ adj.resize(n); for (int i = 0; i < n; ++i){ for (int j = i; j < n; ++j){ if (H[j] > H[i]){ adj[i].push_back(j); break; } } for (int j = i; j >= 0; --j){ if (H[j] > H[i]){ adj[i].push_back(j); break; } } } } int minimum_jumps(int a, int b, int c, int d){ queue<pair<int, int>> q; unordered_set<int> s, f; for (int i = a; i <= b; ++i){ s.insert(i); } for (int i = c; i <= d; ++i){ f.insert(i); } for (int i : s){ q.push({0, i}); } while (!q.empty()){ auto t = q.front(); q.pop(); if (f.find(t.second) != f.end()){ return t.first; } for (int i : adj[t.second]){ q.push({t.first + 1, i}); } } return -1; } /* signed main(){ //cin.tie(0); //iostream::sync_with_stdio(0); int n, q; cin >> n >> q; vector<int> k(n); for (int i = 0; i < n; ++i){ cin >> k[i]; } init(n, k); for (int i = 0; i < q; ++i){ int a, b, c, d; cin >> a >> b >> c >> d; cout << minimum_jumps(a, b, c, d) << endl; } return 0; } */
#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...