#include <bits/stdc++.h>
#include "books.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using plpii = pair<ll, pii>;
const int N = 1e6+10;
const ll INF = 1e9;
int qs[N];
ll minimum_walk(vector<int> p, int s)
{
int n = p.size();
bool ok = true;
for (int i = 0; i < n; ++i) if (p[i] != i) {
ok = false;
break;
}
if (ok) return 0;
ll dist = 0;
for (int i = 0; i < n; ++i) {
if (p[i] == -1) continue;
if (p[i] == i) continue;
int u = i;
while (p[u] != -1) {
int v = p[u];
dist += abs(u-v);
p[u] = -1;
qs[min(u, v)] += 1;
qs[max(u, v)] -= 1;
u = v;
}
}
int mn = INF;
int last = 0;
for (int i = 0; i < n; ++i) {
if (i > 0) qs[i] += qs[i-1];
if (last != -1 && p[i] == -1) {
mn = min(mn, abs(s-i));
if (last != 0)
dist += 2*(i-last);
last = -1;
}
if (qs[i] == 0 && p[i] == -1) {
mn = min(mn, abs(s-i));
last = i;
}
if (p[i] == i && qs[i] == 0)
mn = 0;
}
dist += 2*mn;
return dist;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
248 KB |
3rd lines differ - on the 1st token, expected: '6', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
248 KB |
3rd lines differ - on the 1st token, expected: '6', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
248 KB |
3rd lines differ - on the 1st token, expected: '6', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
484 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '3594' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
248 KB |
3rd lines differ - on the 1st token, expected: '6', found: '4' |
2 |
Halted |
0 ms |
0 KB |
- |