Submission #743521

#TimeUsernameProblemLanguageResultExecution timeMemory
743521onebit1024Rainforest Jumps (APIO21_jumps)C++17
33 / 100
4011 ms15120 KiB
#include "jumps.h" #include <bits/stdc++.h> using namespace std; // #define int long long #define pb push_back #define all(c) c.begin(), c.end() #define endl "\n" const double PI=3.141592653589; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif vector<vector<int>>adj; int n; void init(int N, std::vector<int> H) { n = N; vector<int>a = {0}; adj.resize(N+1); for(auto x : H)a.pb(x); stack<int>st; for(int i = 1;i<=N;++i){ while(!st.empty() && a[i] > a[st.top()])st.pop(); if(!st.empty())adj[i].pb(st.top()); st.push(i); } while(!st.empty())st.pop(); for(int i = N;i>=1;--i){ while(!st.empty() && a[i] > a[st.top()])st.pop(); if(!st.empty())adj[i].pb(st.top()); st.push(i); } } int minimum_jumps(int A, int B, int C, int D) { queue<int>q; vector<int>visited(n+1),dist(n+1,1e9); for(int i = A+1;i<=1+B;++i)q.push(i),dist[i] = 0; while(!q.empty()){ int u = q.front(); q.pop(); if(visited[u])continue; visited[u] = 1; for(int v : adj[u]){ dist[v] = min(dist[v],dist[u]+1); q.push(v); } } int res = 1e9; for(int i = C+1;i<=1+D;++i){ res = min(res, dist[i]); } if(res >= 1e7)return -1; return res; }
#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...