Submission #545376

#TimeUsernameProblemLanguageResultExecution timeMemory
545376AJ00Rainforest Jumps (APIO21_jumps)C++14
33 / 100
4081 ms14384 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<int>> adj(200001); vector<bool> visited(200001,false); vector<int> dist(200001); int n; int minimum_jumps(int A, int B, int C, int D){ int a= A+1,b=B+1,c=C+1,d=D+1; queue<int> q; // cout << a << " " << b << " " << c << " " << d << "\n"; for (int i = 1; i <= n; i++){ visited[i] = false; } /* if (a <= c <= b || a <= d <= b){ return 0; }*/ for (int i = a; i <= b; i++){ q.push(i); dist[i] = 0; if ((c <= i) && (i <= d)){ return 0; } visited[i] = true; } while(!q.empty()){ int p = q.front(); q.pop(); // cout << p << " " << dist[p] << "\n"; for (int ch: adj[p]){ if (!visited[ch]){ visited[ch] = true; q.push(ch); dist[ch] = dist[p]+1; //cout << ch << " " << dist[ch] << "\n"; if ((c <= ch) && (ch<= d)){ return dist[ch]; } } } } return -1; } void init(int N, vector<int> H){ n = N; stack<int> st; for (int i = 1; i <= n; i++){ while(!st.empty() && H[st.top()-1] < H[i-1]){ st.pop(); } if (!st.empty()){ adj[i].push_back(st.top()); } st.push(i); } while(!st.empty()){ st.pop(); } for (int i = n; i>=1; i--){ while(!st.empty() && H[st.top()-1] < H[i-1]){ st.pop(); } if (!st.empty()){ adj[i].push_back(st.top()); } st.push(i); } /* for (int i = 1; i <= n; i++){ for (int j = 0; j < adj[i].size(); j++){ cout << adj[i][j] << " "; } cout << "\n"; }*/ }
#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...