#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll minimum_walk(vector<int> p, int s) {
int nums = p.size();
vector<int> cyc(nums, -1);
ll ans = 0;
int mn = s, mx = s;
for (int i = 0; i < nums; i++)
if (cyc[i] == -1){
int curr = i; bool sg = (p[i] == i);
do{
ans += abs(curr - p[curr]);
cyc[curr] = i;
if (!sg){
mn = min(mn, curr);
mx = max(mn, curr);
}
curr = p[curr];
} while (curr != i);
}
ll cnt = 0;
vector<bool> vis(nums, 0);
for (int i = 0; i < nums; i++)
if (!vis[cyc[i]]){
vis[cyc[i]] = 1;
if (i >= mn && i <= mx) cnt++;
}
return ans + (cnt - 1) * 2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 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 |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 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 |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 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 |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '4182' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |