#include "books.h"
#include<vector>
#include<cstdlib>
#include<climits>
long long minimum_walk(std::vector<int> p, int s) {
if(s!=0)return -1;
std::vector<char> vs(p.size());
int max_cr=0;
long long sbookmove=0;
for(int i=p.size();i--;){
sbookmove+=std::abs(i-p[i]);
if(vs[i])continue;
int cr=INT_MAX; // closest to the right
for(int j=i;;){
vs[j]=true;
cr=std::min(cr,j);
j=p[j];
if(j==i)break;
}
max_cr=std::max(max_cr,cr);
}
return sbookmove+2*max_cr;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '-1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |