Submission #1317991

#TimeUsernameProblemLanguageResultExecution timeMemory
1317991aris12345678Rainforest Jumps (APIO21_jumps)C++17
8 / 100
4075 ms1114112 KiB
#include <bits/stdc++.h> using namespace std; int n; vector<int> height; vector<vector<int>> adj; void init(int N, vector<int> H) { n = N; height = H; } int bfs(int start, int tar1, int tar2) { queue<pair<int, int>> q; vector<bool> vis(n, false); q.push({start, 0}); int ans = INT_MAX; while(!q.empty()) { int u = q.front().first, value = q.front().second; q.pop(); if(vis[u]) continue; vis[u] = true; if(u >= tar1 && u <= tar2) { ans = min(ans, value); continue; } for(int i = 0; i < adj[u].size(); i++) q.push({adj[u][i], value+1}); } return ans; } int minimum_jumps(int A, int B, int C, int D) { // if(sub1()) return C-B; adj.resize(n); for(int i = 0; i < n; i++) { for(int j = i-1; j >= 0; j--) { if(height[j] > height[i]) { adj[i].push_back(j); break; } } for(int j = i+1; j < n; j++) { if(height[j] > height[i]) { adj[i].push_back(j); break; } } } int ans = INT_MAX; for(int i = A; i <= B; i++) ans = min(ans, bfs(i, C, D)); if(ans == INT_MAX) return -1; return ans; } // int main() { // int N, Q; // scanf("%d %d", &N, &Q); // vector<int> H(N); // for(int i = 0; i < N; i++) // scanf("%d", &H[i]); // init(N, H); // while(Q--) { // int A, B, C, D; // scanf("%d %d %d %d", &A, &B, &C, &D); // printf("%d\n", minimum_jumps(A, B, C, D)); // } // return 0; // }
#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...