#include "books.h"
#include<bits/stdc++.h>
using namespace std;
long long minimum_walk(vector<int> p, int s) {
int ans = 0, n = p.size();
int i = 0;
while(i < n) {
if (p[i] == i) {
i++;
if (i != n) {
ans++;
}
continue;
}
int a = i;
while(p[a] != a) {
ans += abs(p[a]-a);
int b = p[a];
p[a] = a;
a = b;
}
if (is_sorted(p.begin(), p.end())) {
break;
}
i = a;
i++;
if (i != n) {
ans++;
}
}
if (i == n) {
i--;
}
while(i >= 0) {
if (p[i] == i) {
i--;
if (i < 0) {
ans++;
}
continue;
}
int a = i;
while(p[a] != a) {
ans += abs(p[a]-a);
int b = p[a];
p[a] = a;
a = b;
}
i = a;
i--;
if (i < 0) {
ans++;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '8', found: '9' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '8', found: '9' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '8', found: '9' |
4 |
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: '3737' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '8', found: '9' |
4 |
Halted |
0 ms |
0 KB |
- |