제출 #984041

#제출 시각아이디문제언어결과실행 시간메모리
984041Marcus밀림 점프 (APIO21_jumps)C++17
8 / 100
16 ms5208 KiB
#include "jumps.h" #include <vector> #include <bits/stdc++.h> using namespace std; int n; vector<int> h; const int INF = 2e6; vector<vector<int>> adj(200, vector<int>(200, INF)); vector<vector<int>> dist(200, vector<int>(200, INF)); void init(int N, std::vector<int> H) { n = N; for (auto u: H) {h.push_back(u);} h.shrink_to_fit(); for (int i=0; i<n; i++) { for (int j=i; j<n; j++) { if (h[i] < h[j]) {adj[i][j] = 1; break;}; } for (int j=i; j>=0; j--) { if (h[i] < h[j]) {adj[i][j] = 1; break;}; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i == j) dist[i][j] = 0; else if (adj[i][j]) dist[i][j] = adj[i][j]; else dist[i][j] = INF; } } for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]); } } } } int minimum_jumps(int A, int B, int C, int D) { int answer = INF; for (int i=A; i<=B; i++) { for (int j=C; j<=D; j++) { answer = min(answer, dist[i][j]); } } return (answer >= INF ? -1 : answer); }
#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...