Submission #972275

#TimeUsernameProblemLanguageResultExecution timeMemory
972275akacool445kRainforest Jumps (APIO21_jumps)C++14
0 / 100
4 ms6316 KiB
#include <bits/stdc++.h> #include "jumps.h" using namespace std; // #define int long long #define ff first #define ss second const int shrek = 2e5; vector<int> h (shrek); int l[shrek], r[shrek]; int n; set<pair<int, int>> pos, neg; int spx[19][shrek]; int spn[19][shrek]; void init(int N, vector<int> H) { n = N; for(int i = 0; i < N; i++) { h[i] = H[i]; r[i] = -1; l[i] = -1; } vector<int> v; for(int i = 0; i < n; i++) { while(v.back()< h[i] && !v.empty()) { r[v.back()] = h[i]; v.pop_back(); } if(!v.empty()) l[i] = v.back(); v.push_back(h[i]); } for(int i = 0; i < n; i++) { spx[0][h[i]] = max(l[h[i]], r[h[i]]); spn[0][h[i]] = min(l[h[i]], r[h[i]]); } for(int j = 1; j < 19; j++) { for(int i = 0; i < n; i++) { spx[j][h[i]] = spx[j - 1][spx[j - 1][h[i]]]; spn[j][h[i]] = spn[j - 1][spn[j - 1][h[i]]]; } } } int minimum_jumps(int a, int b, int c, int d) { if(h[a] > h[c]) return -1; int dis = 0; for(int i = 18; i >= 0; i--) { if(spx[i][h[a]] > h[d]) continue; if(spx[i][h[a]] == h[d]) return (1 << i); return (1 << i) + minimum_jumps(spx[i][h[a]], b, c, d); } for(int i = 18; i >= 0; i--) { if(spn[i][h[a]] > h[d]) continue; if(spn[i][h[a]] == h[d]) return (1 << i); return (1 << i) + minimum_jumps(spn[i][h[a]], b, c, d); } return -1; }

Compilation message (stderr)

jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:45:9: warning: unused variable 'dis' [-Wunused-variable]
   45 |     int dis = 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...