#include "jumps.h"
using namespace std;
#include <vector>
#include <queue>
#include <iostream>
#define NMAX 20000
// #define NMAX 7
#define INF 1e9
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 |
1 |
Runtime error |
438 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
440 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
440 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
435 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
460 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
460 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
438 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |