Submission #1054323

#TimeUsernameProblemLanguageResultExecution timeMemory
1054323stdfloatRainforest Jumps (APIO21_jumps)C++17
21 / 100
4094 ms1048576 KiB
#include <bits/stdc++.h> #include "jumps.h" using namespace std; vector<vector<int>> E, dis; void init(int n, vector<int> v) { E.assign(n, {}); for (int i = 0; i < n; i++) { for (int j = i - 1; j >= 0; j--) { if (v[i] < v[j]) { E[i].push_back(j); break; } } for (int j = i + 1; j < n; j++) { if (v[i] < v[j]) { E[i].push_back(j); break; } } } dis.assign(n, vector<int>(n, INT_MAX)); for (int i = 0; i < n; i++) { queue<int> q; q.push(i); dis[i][i] = 0; while (!q.empty()) { int x = q.front(); q.pop(); for (auto j : E[x]) { if (dis[i][j] == INT_MAX) { dis[i][j] = dis[i][x] + 1; q.push(j); } } } } } int minimum_jumps(int A, int B, int C, int D) { int mn = INT_MAX; for (int i = A; i <= B; i++) { for (int j = C; j <= D; j++) { mn = min(mn, dis[i][j]); } } return (mn == INT_MAX ? -1 : mn); }
#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...