Submission #960648

#TimeUsernameProblemLanguageResultExecution timeMemory
960648Trisanu_DasRainforest Jumps (APIO21_jumps)C++17
Compilation error
0 ms0 KiB
#include "jumps.h" #include<bits/stdc++.h> using namespace std; #define ff first #define ss second int n, int dist[200005], l[200005], r[200005]; vector<pair<int, int> > h; bool inc = true; void init(int N, vector<int> H) { n = N; for(int i = 0; i < n; i++){ h.push_back({H[i], i + 1}); if(H[i] != i + 1) inc = false; } sort(h.rbegin(), h.rend()); set<pair<int, int> > s; for(auto [x, idx] : h){ if(s.empty()){ s.insert({idx, x}); continue; } auto it = s.lower_bound({idx, 0}); if(it != s.end()) r[x] = (*it).ss; if(it != s.begin()){ it--; l[x] = (*it).ss; } s.insert({idx, x}); } } int minimum_jumps(int a, int b, int c, int d) { if(inc) return c - b; int ans = INT_MAX; a++; b++; c++; d++; for(int i = 0; i < n; i++) dist[i] = INT_MAX; for(auto [x, idx] : h){ if(c <= idx && idx <= d) dist[x] = 0; if(a <= idx && idx <= b) ans = min({ans, dist[l[x]] + 1, dist[r[x]] + 1}); dist[x] = min({dist[x], dist[l[x]] + 1, dist[r[x]] + 1}); } return ans == INT_MAX ? -1 : ans; }

Compilation message (stderr)

jumps.cpp:7:8: error: expected unqualified-id before 'int'
    7 | int n, int dist[200005], l[200005], r[200005];
      |        ^~~
jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:24:23: error: 'r' was not declared in this scope
   24 |     if(it != s.end()) r[x] = (*it).ss;
      |                       ^
jumps.cpp:26:13: error: 'l' was not declared in this scope
   26 |       it--; l[x] = (*it).ss;
      |             ^
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:35:30: error: 'dist' was not declared in this scope
   35 |   for(int i = 0; i < n; i++) dist[i] = INT_MAX;
      |                              ^~~~
jumps.cpp:37:30: error: 'dist' was not declared in this scope
   37 |     if(c <= idx && idx <= d) dist[x] = 0;
      |                              ^~~~
jumps.cpp:38:46: error: 'dist' was not declared in this scope
   38 |     if(a <= idx && idx <= b) ans = min({ans, dist[l[x]] + 1, dist[r[x]] + 1});
      |                                              ^~~~
jumps.cpp:38:51: error: 'l' was not declared in this scope
   38 |     if(a <= idx && idx <= b) ans = min({ans, dist[l[x]] + 1, dist[r[x]] + 1});
      |                                                   ^
jumps.cpp:38:67: error: 'r' was not declared in this scope
   38 |     if(a <= idx && idx <= b) ans = min({ans, dist[l[x]] + 1, dist[r[x]] + 1});
      |                                                                   ^
jumps.cpp:38:77: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   38 |     if(a <= idx && idx <= b) ans = min({ans, dist[l[x]] + 1, dist[r[x]] + 1});
      |                                                                             ^
In file included from /usr/include/c++/10/vector:60,
                 from jumps.h:1,
                 from jumps.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
jumps.cpp:38:77: note:   candidate expects 2 arguments, 1 provided
   38 |     if(a <= idx && idx <= b) ans = min({ans, dist[l[x]] + 1, dist[r[x]] + 1});
      |                                                                             ^
In file included from /usr/include/c++/10/vector:60,
                 from jumps.h:1,
                 from jumps.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
jumps.cpp:38:77: note:   candidate expects 3 arguments, 1 provided
   38 |     if(a <= idx && idx <= b) ans = min({ans, dist[l[x]] + 1, dist[r[x]] + 1});
      |                                                                             ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from jumps.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
jumps.cpp:39:5: error: 'dist' was not declared in this scope
   39 |     dist[x] = min({dist[x], dist[l[x]] + 1, dist[r[x]] + 1});
      |     ^~~~
jumps.cpp:39:34: error: 'l' was not declared in this scope
   39 |     dist[x] = min({dist[x], dist[l[x]] + 1, dist[r[x]] + 1});
      |                                  ^
jumps.cpp:39:50: error: 'r' was not declared in this scope
   39 |     dist[x] = min({dist[x], dist[l[x]] + 1, dist[r[x]] + 1});
      |                                                  ^
jumps.cpp:39:60: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   39 |     dist[x] = min({dist[x], dist[l[x]] + 1, dist[r[x]] + 1});
      |                                                            ^
In file included from /usr/include/c++/10/vector:60,
                 from jumps.h:1,
                 from jumps.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
jumps.cpp:39:60: note:   candidate expects 2 arguments, 1 provided
   39 |     dist[x] = min({dist[x], dist[l[x]] + 1, dist[r[x]] + 1});
      |                                                            ^
In file included from /usr/include/c++/10/vector:60,
                 from jumps.h:1,
                 from jumps.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
jumps.cpp:39:60: note:   candidate expects 3 arguments, 1 provided
   39 |     dist[x] = min({dist[x], dist[l[x]] + 1, dist[r[x]] + 1});
      |                                                            ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from jumps.cpp:2:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed: