#include "books.h"
#define N 1000005
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans = 0;
int n, maior[N], qtd = 0, ok[N], en;
vector<int> g;
void dfs(int x, int &mx)
{
mx = max(mx, x);
if(ok[x]) return;
ok[x] = 1;
dfs(g[x], mx);
}
ll minimum_walk(vector<int> p, int s)
{
n = p.size();
g = p;
for(int i = 0; i < n; i++) ans += abs(i - p[i]);
for(int i = 0; i < n; i++) dfs(i, maior[i]);
for(int i = n - 1; i >= 0; i--)
{
if(p[i] != i)
{
en = i;
break;
}
}
ll pos = 0, qtd = 0;
while(pos <= en)
{
pos = maior[pos] + 1;
qtd ++;
}
return ans + 2*(qtd - 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
528 KB |
Output is correct |
6 |
Correct |
3 ms |
532 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
752 KB |
Output is correct |
11 |
Correct |
2 ms |
756 KB |
Output is correct |
12 |
Correct |
2 ms |
760 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
3 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
2 ms |
776 KB |
Output is correct |
17 |
Correct |
3 ms |
900 KB |
Output is correct |
18 |
Correct |
3 ms |
900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
528 KB |
Output is correct |
6 |
Correct |
3 ms |
532 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
752 KB |
Output is correct |
11 |
Correct |
2 ms |
756 KB |
Output is correct |
12 |
Correct |
2 ms |
760 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
3 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
2 ms |
776 KB |
Output is correct |
17 |
Correct |
3 ms |
900 KB |
Output is correct |
18 |
Correct |
3 ms |
900 KB |
Output is correct |
19 |
Incorrect |
4 ms |
900 KB |
3rd lines differ - on the 1st token, expected: '338572', found: '338578' |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
528 KB |
Output is correct |
6 |
Correct |
3 ms |
532 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
752 KB |
Output is correct |
11 |
Correct |
2 ms |
756 KB |
Output is correct |
12 |
Correct |
2 ms |
760 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
3 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
2 ms |
776 KB |
Output is correct |
17 |
Correct |
3 ms |
900 KB |
Output is correct |
18 |
Correct |
3 ms |
900 KB |
Output is correct |
19 |
Incorrect |
4 ms |
900 KB |
3rd lines differ - on the 1st token, expected: '338572', found: '338578' |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
900 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
3 ms |
488 KB |
Output is correct |
5 |
Correct |
3 ms |
528 KB |
Output is correct |
6 |
Correct |
3 ms |
532 KB |
Output is correct |
7 |
Correct |
3 ms |
724 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
3 ms |
752 KB |
Output is correct |
11 |
Correct |
2 ms |
756 KB |
Output is correct |
12 |
Correct |
2 ms |
760 KB |
Output is correct |
13 |
Correct |
2 ms |
764 KB |
Output is correct |
14 |
Correct |
3 ms |
768 KB |
Output is correct |
15 |
Correct |
2 ms |
772 KB |
Output is correct |
16 |
Correct |
2 ms |
776 KB |
Output is correct |
17 |
Correct |
3 ms |
900 KB |
Output is correct |
18 |
Correct |
3 ms |
900 KB |
Output is correct |
19 |
Incorrect |
4 ms |
900 KB |
3rd lines differ - on the 1st token, expected: '338572', found: '338578' |
20 |
Halted |
0 ms |
0 KB |
- |