Submission #922182

#TimeUsernameProblemLanguageResultExecution timeMemory
922182ArpRainforest Jumps (APIO21_jumps)C++17
Compilation error
0 ms0 KiB
const int N = 2e5; int ml[N],mr[N]; int best[N]; int arr[N]; void init(int n,vector<int> a){ for(int i = 0;i<n;i++){ ml[i] = -1; mr[i] = n; arr[i] = a[i]; } stack<int> lg; for(int i = 0;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 - 1;i >= 0;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 = 0;i<n;i++){ best[i] = (ml[i] > mr[i] ? ml[i] : mr[i]); } } int minimum_jumps(int a,int b,int c,int d){ int m2 = b; for(int i = c;i <= d;i ++){ if(arr[i] > arr[m2]) m2 = i; } int m1 = a; for(int i = a;i <= b;i++){ if(arr[i] > arr[m1] && arr[i] < arr[m2]) m1 = i; } if(arr[m1] > arr[m2]) return -1; int last = m1; int ans = 0; while(arr[best[last]] < arr[m2]){ last = best[last]; ans ++; } while(!(last >= c && last <= d)){ if(arr[last] > arr[m2]) return -1; last = mr[last]; ans ++; } return ans; }

Compilation message (stderr)

jumps.cpp:7:17: error: 'vector' has not been declared
    7 | void init(int n,vector<int> a){
      |                 ^~~~~~
jumps.cpp:7:23: error: expected ',' or '...' before '<' token
    7 | void init(int n,vector<int> a){
      |                       ^
jumps.cpp: In function 'void init(int, int)':
jumps.cpp:11:14: error: 'a' was not declared in this scope
   11 |     arr[i] = a[i];
      |              ^
jumps.cpp:13:3: error: 'stack' was not declared in this scope
   13 |   stack<int> lg;
      |   ^~~~~
jumps.cpp:13:9: error: expected primary-expression before 'int'
   13 |   stack<int> lg;
      |         ^~~
jumps.cpp:15:11: error: 'lg' was not declared in this scope
   15 |     while(lg.size() > 0 && arr[lg.top()] < arr[i]) lg.pop();
      |           ^~
jumps.cpp:16:8: error: 'lg' was not declared in this scope
   16 |     if(lg.size() > 0){
      |        ^~
jumps.cpp:19:5: error: 'lg' was not declared in this scope
   19 |     lg.push(i);
      |     ^~
jumps.cpp:21:9: error: expected primary-expression before 'int'
   21 |   stack<int> rg;
      |         ^~~
jumps.cpp:23:11: error: 'rg' was not declared in this scope
   23 |     while(rg.size() > 0 && arr[rg.top()] < arr[i]) rg.pop();
      |           ^~
jumps.cpp:24:8: error: 'rg' was not declared in this scope
   24 |     if(rg.size() > 0){
      |        ^~
jumps.cpp:27:5: error: 'rg' was not declared in this scope
   27 |     rg.push(i);
      |     ^~