#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();
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 + 1 < n; i ++) {
if(p[i] == i and i != s) continue;
int ptr = i + 1, mx = i;
while(ptr <= G[i] or (ptr != s and ptr < n and p[ptr] == ptr)) {
if(ptr <= G[i]) mx = ptr;
G[i] = max(G[i], G[ptr]);
ptr ++;
}
if(ptr < n) sum += ptr - mx;
i = ptr - 1;
}
return sum;
}
//main () {
// cout << minimum_walk({2, 3, 0, 1}, 0);
//}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |