Submission #711621

#TimeUsernameProblemLanguageResultExecution timeMemory
711621irmuunRainforest Jumps (APIO21_jumps)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> //include "roads.h" using namespace std; #define pb push_back #define ll long long #define ff first #define ss second #define PI 3.1415926535897932384626433 #define all(s) s.begin(),s.end() const int maxn=200000,INF=1e9; bool ok=true; vector<int>adj[maxn+5]; int n,used[maxn+5],dist[maxn+5]; void dfs(int a,int b,int c,int d){ queue<int>q; fill(used,used+n+1,0); fill(dist,dist+n+1,0); for(int i=a;i<=b;i++) q.push(i); while(!q.empty()){ int x=q.front(); q.pop(); if(c<=x&&x<=d) return dist[X]; for(auto u:adj[x]){ if(dist[u]==INF){ dist[u]=dist[x]+1; q.push(u); } } } return -1; } void init(int N,vector<int>H){ n=N; for(int i=0;i<n;i++){ if(H[i]!=i+1) ok=false; } stack<pair<int,int>>s; for(int i=0;i<n;i++){ while(!S.empty()&&s[i].ff<H[i]) S.pop(); if(!S.empty()) adj[i].pb(S.top().ss); s.push({H[i],i}); } while(!S.empty()) S.pop(); for(int i=n-1;i>=0;i--){ while(!S.empty()&&s[i].ff<H[i]) S.pop(); if(!S.empty()) adj[i].pb(S.top().ss); s.push({H[i],i}); } } int minimum_jumps(int A, int B, int C, int D){ if(ok==true){ return C-B; } return dfs(A,B,C,D); }

Compilation message (stderr)

jumps.cpp: In function 'void dfs(int, int, int, int)':
jumps.cpp:23:36: error: 'X' was not declared in this scope
   23 |         if(c<=x&&x<=d) return dist[X];
      |                                    ^
jumps.cpp:31:12: error: return-statement with a value, in function returning 'void' [-fpermissive]
   31 |     return -1;
      |            ^~
jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:40:16: error: 'S' was not declared in this scope
   40 |         while(!S.empty()&&s[i].ff<H[i]) S.pop();
      |                ^
jumps.cpp:40:28: error: no match for 'operator[]' (operand types are 'std::stack<std::pair<int, int> >' and 'int')
   40 |         while(!S.empty()&&s[i].ff<H[i]) S.pop();
      |                            ^
jumps.cpp:41:13: error: 'S' was not declared in this scope
   41 |         if(!S.empty()) adj[i].pb(S.top().ss);
      |             ^
jumps.cpp:44:12: error: 'S' was not declared in this scope
   44 |     while(!S.empty()) S.pop();
      |            ^
jumps.cpp:46:16: error: 'S' was not declared in this scope
   46 |         while(!S.empty()&&s[i].ff<H[i]) S.pop();
      |                ^
jumps.cpp:46:28: error: no match for 'operator[]' (operand types are 'std::stack<std::pair<int, int> >' and 'int')
   46 |         while(!S.empty()&&s[i].ff<H[i]) S.pop();
      |                            ^
jumps.cpp:47:13: error: 'S' was not declared in this scope
   47 |         if(!S.empty()) adj[i].pb(S.top().ss);
      |             ^
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:55:15: error: void value not ignored as it ought to be
   55 |     return dfs(A,B,C,D);
      |            ~~~^~~~~~~~~