#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1000000;
bool vis[N];
long long minimum_walk(std::vector<int> p, int s) {
ll res = 0;
int n = p.size();
for (int i = 0; i < n; i++)
{
if (p[i] == i || vis[i]) continue;
int cur = i;
do
{
vis[cur] = true;
res += abs(p[cur] - cur);
cur = p[cur];
} while (cur != i);
}
if (res == 0) return 0;
int first = -1;
int last = -1;
for (int i = 0; i < n; i++)
{
if (vis[i])
{
first = i;
break;
}
}
for (int i = n - 1; i >= 0; i--)
{
if (vis[i])
{
last = i;
break;
}
}
for (int i = n - 1; i >= 0; i--)
{
if (!vis[i])
{
if (i <= last)
{
if (i < first) res++;
else res += 2;
}
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '3824' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |