#include <bits/stdc++.h>
#include "books.h"
using namespace std;
const int MX = 1e6 + 100;
int G[MX];
long long minimum_walk(vector<int> p, int s) {
int n = p.size();
while(p[n - 1] == n - 1 and n - 1 > s) n --;
long long sum = 0;
for(int i = 0; i < n; i ++) {
G[p[i]] = max(G[p[i]], i);
G[i] = max(G[i], p[i]);
sum += abs(i - p[i]);
}
for(int i = 0; i < n; i ++) {
if(p[i] == i and i < s) continue;
int ptr = i + 1;
while(ptr <= G[i]) {
G[i] = max(G[i], G[ptr]);
ptr ++;
}
if(ptr < n) sum += 2;
i = ptr - 1;
}
int mn = MX;
for(int i = s; i < n; i ++) if(p[i] != i) mn = min(mn, i - s);
for(int i = s; i >= 0; i --) if(p[i] != i) mn = min(mn, s - i);
return sum + mn;
}
//main () {
// cout << minimum_walk({2, 3, 0, 1}, 0);
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
280 KB |
3rd lines differ - on the 1st token, expected: '6', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
280 KB |
3rd lines differ - on the 1st token, expected: '6', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
280 KB |
3rd lines differ - on the 1st token, expected: '6', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
280 KB |
3rd lines differ - on the 1st token, expected: '6', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |