// Ignut
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll minimum_walk(vector<int> p, int s) {
int n = p.size();
int cntR[n] = {}, cntL[n] = {};
int add[n] = {}, del[n] = {};
// right
for (int i = 0; i < n; i ++) {
if (p[i] > i) {
add[i] ++;
del[p[i]] ++;
}
}
int cr = 0;
for (int i = 0; i < n; i ++) {
cr += add[i];
cr -= del[i];
cntR[i] = cr;
}
// left
for (int i = 0; i < n; i ++) add[i] = del[i] = 0;
for (int i = 0; i < n; i ++) {
if (p[i] < i) {
add[i] ++;
del[p[i]] ++;
}
}
int cl = 0;
for (int i = n - 1; i >= 0; i --) {
cl += add[i];
cl -= del[i];
cntL[i] = cl;
}
ll res = 0;
int pos = 0;
while (true) {
int R = -1;
for (int i = 0; i < n; i ++) if (cntR[i] >= 1) R = i + 1;
for (int i = 0; i < n; i ++) if (cntL[i] >= 1) R = max(R, i);
if (R < pos) break;
for (int i = pos; i < R; i ++) cntR[i] --;
res += R - pos;
pos = R;
int L = 2 * n + 123;
for (int i = n - 1; i >= 0; i --) if (cntL[i] >= 1) L = i - 1;
for (int i = n - 1; i >= 0; i --) if (cntR[i] >= 1) L = min(L, i);
if (L > pos) break;
res += pos - L;
for (int i = pos; i > L; i --) cntL[i] --;
pos = L;
}
res += pos;
return res;
}
# |
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: '10' |
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: '10' |
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: '10' |
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: '5936' |
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: '10' |
4 |
Halted |
0 ms |
0 KB |
- |