Submission #922286

#TimeUsernameProblemLanguageResultExecution timeMemory
922286ArpRainforest Jumps (APIO21_jumps)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int ml[N],mr[N]; int best[N]; int arr[N]; const int inf = 1e9; int MAXN; bool one = true; void init(int n,vector<int> a){ for(int i = 1;i<=n;i++){ ml[i] = 0; mr[i] = n + 1; arr[i] = a[i - 1]; one &= (arr[i] == i); } MAXN = n; arr[0] = arr[n + 1] = -1; stack<int> lg; for(int i = 1;i<=n;i++){ while(lg.size() > 0 && arr[lg.top()] < arr[i]) lg.pop(); if(lg.size() > 0){ ml[i] = lg.top(); } lg.push(i); } stack<int> rg; for(int i = n;i >= 1;i--){ while(rg.size() > 0 && arr[rg.top()] < arr[i]) rg.pop(); if(rg.size() > 0){ mr[i] = rg.top(); } rg.push(i); } for(int i = 1;i<=n;i++){ best[i] = (arr[ml[i]] > arr[mr[i]] ? ml[i] : mr[i]); // cout << best[i] << " "; } // cout << '\n'; } int minimum_jumps(int a,int b,int c,int d){ a ++,b ++; c ++,d ++; // if(one) return c - b; int m2 = c; for(int i = c;i <= d;i ++){ if(arr[i] > arr[m2]) m2 = i; } int m1 = MAXN + 1; for(int i = a;i <= b;i++){ if(arr[i] > arr[m1] && arr[i] < arr[m2]) m1 = i; } if(m1 == MAXN + 1){ assert(!ok); return -1; } int last = m1; int ans = 0; while(arr[best[last]] < arr[m2]){ if(last >= c && last <= d) return ans; if(mr[last] >= c && mr[last] <= d) return ans + 1; last = best[last]; assert(last < d && last != MAXN); ans ++; } while(!(last >= c && last <= d)){ if(arr[last] > arr[m2] || last > d) return -1; last = mr[last]; ans ++; } return ans; }

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from jumps.cpp:1:
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:56:13: error: 'ok' was not declared in this scope
   56 |     assert(!ok);
      |             ^~