#include "books.h"
#include <bits/stdc++.h>
using namespace std;
long long minimum_walk(vector<int>p, int s) {
long long last = 0;
int n = p.size();
long long ans = 0;
vector<bool>vis(n,0);
int mx = -1;
for(int i = 0 ; i < n ; i++) if(!vis[i]) {
vis[i] = 1;
if(i > mx)
last = i;
int pos = i;
do {
vis[pos] = 1;
mx = max(mx, pos);
int nxt = p[pos];
ans += abs(nxt-pos);
pos = nxt;
} while(pos != i);
}
return ans+2*last;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
296 KB |
3rd lines differ - on the 1st token, expected: '4', found: '10' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
296 KB |
3rd lines differ - on the 1st token, expected: '4', found: '10' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
296 KB |
3rd lines differ - on the 1st token, expected: '4', found: '10' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
216 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 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
0 ms |
296 KB |
3rd lines differ - on the 1st token, expected: '4', found: '10' |
6 |
Halted |
0 ms |
0 KB |
- |