This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "jumps.h"
using namespace std;
#include <vector>
#include <queue>
#include <iostream>
#define NMAX 2010
// #define NMAX 7
#define INF 1e5
vector<vector<int>> costs(NMAX,vector<int>(NMAX,INF));
vector<vector<int>> paths(NMAX,vector<int>(NMAX,0));
void init(int N, std::vector<int> H) {
for(int i = 0;i<N;i++)costs[i][i] = 0;
for(int i = 0;i<N;i++){
int pos = i+1;
while(pos<N){
if(H[i]<H[pos]){
paths[i][pos] = 1;
costs[i][pos] = 1;
break;
}pos++;
}
pos = i-1;
while(pos>-1){
if(H[i]<H[pos]){
paths[i][pos] = 1;
costs[i][pos] = 1;
break;
}pos--;
}
}
// for(int i=0;i<costs.size();i++){
// for(int j=0;j<costs[i].size();j++){
// cout << costs[i][j] << " ";
// }cout << endl;
// }
// for(int i=0;i<N;i++){
// cout << i << " -> ";
// for(int j=0;j<paths[i].size();j++){
// cout << paths[i][j] << ",";
// }cout << endl;
// }
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
for(int k=0;k<N;k++){
costs[i][j] = min(costs[i][j],costs[i][k]+costs[k][j]);
}
}
}
// for(int i=0;i<costs.size();i++){
// for(int j=0;j<costs[i].size();j++){
// cout << costs[i][j] << " ";
// }cout << endl;
// }
}
int minimum_jumps(int A, int B, int C, int D) {
int ans = INF;
for(int i=A;i<=B;i++){
for(int j=C;j<=D;j++){
ans = min(ans,costs[i][j]);
}
}
if(ans == INF)return -1;
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |