#include "books.h"
struct Par
{
int l, r;
};
int abs(int x) { return x < 0 ? -x : x; }
std::vector<Par> segmentos;
long long minimum_walk(std::vector<int> p, int s) {
int n = (int)p.size();
long long ans = 0;
bool ok = 1;
for(int i = 0, ini = 0, fim = 0; i < n; i++) {
if(p[i] == i) { ++ini; continue; }
fim = std::max(fim, p[i]);
ans += abs(p[i] - i);
if(fim == i) {
if(ok && ini >= s) segmentos.push_back({s, s}), ok = 0;
segmentos.push_back({ini, fim}), ini = i+1;
if(ini <= s && fim >= s) ok = 0;
}
}
for(int i = 0; i < ((int)segmentos.size()) - 1; i++)
ans += 2*(segmentos[i+1].l - segmentos[i].r);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
284 KB |
Output is correct |
2 |
Incorrect |
1 ms |
284 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 |
1 ms |
284 KB |
Output is correct |
2 |
Incorrect |
1 ms |
284 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 |
1 ms |
284 KB |
Output is correct |
2 |
Incorrect |
1 ms |
284 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 |
1 ms |
284 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2974' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
284 KB |
Output is correct |
2 |
Incorrect |
1 ms |
284 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |