#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll minimum_walk(vector<int> p, int s) {
ll ans = 0;
int n = (int)p.size();
vector<vector<int>> cycles {};
vector<bool> vis (n, false);
int last = 0;
for (int i = 0; i < n; i++) {
if (vis[i])
continue;
ans += abs(i - last);
int pos = i;
last = i;
cycles.push_back({});
while (!vis[pos]) {
vis[pos] = true;
cycles.back().push_back(pos);
ans += abs(p[pos] - pos);
pos = p[pos];
}
}
ans += last;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 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 |
296 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 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 |
296 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 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 |
304 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '4736' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |