Submission #1178393

#TimeUsernameProblemLanguageResultExecution timeMemory
1178393MuhammetRainforest Jumps (APIO21_jumps)C++20
23 / 100
509 ms61484 KiB
#include "bits/stdc++.h" #include "jumps.h" // #include "stub.cpp" using namespace std; #define SZ(s) (int)s.size() const int N = 2e5 + 5; int n, x[N][30], m[N][30]; vector <int> h, v[N]; bool tr; void init(int N1, vector<int> H) { n = N1, h = H; vector <int> v1; for(int i = 0; i < n; i++) { while(SZ(v1) and h[v1.back()] < h[i]) { v1.pop_back(); } if(SZ(v1)) v[i].push_back(v1.back()); v1.push_back(i); } v1.clear(); for(int i = n-1; i >= 0; i--) { while(SZ(v1) and h[v1.back()] < h[i]) { v1.pop_back(); } if(SZ(v1)) v[i].push_back(v1.back()); v1.push_back(i); } h.push_back(2*n); x[n][0] = n, m[n][0] = n; for(int i = 0; i < n; i++) { // sort(v[i].begin(), v[i].end()); if(SZ(v[i]) == 2) x[i][0] = (h[v[i][1]] > h[v[i][0]] ? v[i][1] : v[i][0]), m[i][0] = (h[v[i][1]] > h[v[i][0]] ? v[i][0] : v[i][1]); else if(SZ(v[i]) == 1) x[i][0] = v[i][0], m[i][0] = v[i][0]; else x[i][0] = n, m[i][0] = n; } for(int j = 1; j <= 20; j++) { for(int i = 0; i <= n; i++) { x[i][j] = x[x[i][j-1]][j-1]; m[i][j] = m[m[i][j-1]][j-1]; } } return; } int minimum_jumps(int a, int b, int c, int d) { int ans = 0; for(int i = 20; i >= 0; i--) { if(h[x[a][i]] <= h[c]) a = x[a][i], ans += (1<<i); } for(int i = 20; i >= 0; i--) { if(h[m[a][i]] <= h[c]) a = m[a][i], ans += (1<<i); } return (a != c ? -1 : 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...