Submission #439022

#TimeUsernameProblemLanguageResultExecution timeMemory
439022aris12345678Rainforest Jumps (APIO21_jumps)C++14
4 / 100
1168 ms2624 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 200005; bool sub1 = false; vector<int> height; void init(int n, vector<int> h) { if(is_sorted(h.begin(), h.end())) sub1 = true; height = h; return; } int bfs(int i, int end) { int n = int(height.size()); queue<pair<int, int> > q; q.push({i, 0}); while(!q.empty()) { int u = q.front().first, jumps = q.front().second; q.pop(); if(u == end) return jumps; int j = u; while(j >= 0 && height[j] <= height[u]) j--; if(j >= 0) q.push({j, jumps+1}); j = u; while(j < n && height[j] <= height[u]) j++; if(j < n) q.push({j, jumps+1}); } assert(true); } int minimum_jumps(int a, int b, int c, int d) { if(sub1) return c-b; else { int ans = INT_MAX; for(int i = a; i <= b; i++) { int pos = i; for(int j = c; j <= d; j++) { if(height[j] < height[i]) continue; int jumps = bfs(pos, j); ans = min(ans, jumps); } } } } /* 3 2 1 6 4 5 7 (1, 3) (5, 6) */

Compilation message (stderr)

jumps.cpp: In function 'int bfs(int, int)':
jumps.cpp:17:28: warning: control reaches end of non-void function [-Wreturn-type]
   17 |     queue<pair<int, int> > q;
      |                            ^
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
   52 | }
      | ^
#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...