제출 #488780

#제출 시각아이디문제언어결과실행 시간메모리
488780Theo830밀림 점프 (APIO21_jumps)C++17
21 / 100
4067 ms84636 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e9+7; const ll MOD = 998244353; typedef pair<ll,ll> ii; #define iii pair<ii,ll> #define f(i,a,b) for(ll i = a;i < b;i++) #define pb push_back #define vll vector<ll> #define F first #define S second #define all(x) (x).begin(), (x).end() ///I hope I will get uprating and don't make mistakes ///I will never stop programming ///sqrt(-1) Love C++ ///Please don't hack me ///@TheofanisOrfanou Theo830 ///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst) ///Stay Calm ///Look for special cases ///Beware of overflow and array bounds ///Think the problem backwards ///APIO 2021 vc #include "jumps.h" vector<vector<ll> >adj; ll dist[2005][2005]; void bfs(ll s){ queue<ll>q; q.push(s); dist[s][s] = 0; while(!q.empty()){ ll x = q.front(); q.pop(); for(auto y:adj[x]){ if(dist[s][y] == INF){ dist[s][y] = 1 + dist[s][x]; q.push(y); } } } } void init(int N, std::vector<int> H) { adj.assign(N+5,vector<ll>()); f(i,0,N){ f(j,i+1,N){ if(H[j] > H[i]){ adj[i].pb(j); break; } } ll j = i - 1; while(j >= 0){ if(H[j] > H[i]){ adj[i].pb(j); break; } j--; } } f(i,0,N){ f(j,0,N){ dist[i][j] = INF; } } f(i,0,N){ bfs(i); } } int minimum_jumps(int A, int B, int C, int D) { ll ans = INF; f(s,A,B+1){ f(e,C,D+1){ ans = min(ans,dist[s][e]); } } if(ans == INF){ ans = -1; } return ans; }
#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...