#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 10;
int n;
ll ans , ps[MAXN];
ll minimum_walk(vector<int> p, int s) {
n = p.size();
for(int i = 0 ; i < n ; i++){
ps[min(p[i] , i)]++;
ps[max(p[i] , i)]--;
}
partial_sum(ps , ps + MAXN , ps);
int l = 0 , r = n;
while(l < s && ps[l] == 0) l++;
while(s <= r && ps[r] == 0) r--;
int x = p[s] , mn = s , mx = s , res = s;
while(x != s){
mn = min(mn , x);
mx = max(mx , x);
x = p[x];
}
for(int i = 0 ; i < mn ; i++){
if(ps[i] == 0) res = min(res , mn - i - 1);
}
for(int i = mx ; i < n ; i++){
if(ps[i] == 0) res = min(res , i - mx);
}
for(int i = l ; i <= r ; i++){
ans += max(2ll , ps[i]);
}
return ans + res * 2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8092 KB |
Output is correct |
2 |
Correct |
6 ms |
8004 KB |
Output is correct |
3 |
Correct |
6 ms |
8112 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
6 ms |
8012 KB |
Output is correct |
6 |
Correct |
6 ms |
8012 KB |
Output is correct |
7 |
Correct |
6 ms |
8012 KB |
Output is correct |
8 |
Correct |
6 ms |
8012 KB |
Output is correct |
9 |
Correct |
6 ms |
8012 KB |
Output is correct |
10 |
Correct |
6 ms |
8012 KB |
Output is correct |
11 |
Correct |
6 ms |
8012 KB |
Output is correct |
12 |
Correct |
6 ms |
8012 KB |
Output is correct |
13 |
Correct |
6 ms |
8012 KB |
Output is correct |
14 |
Correct |
6 ms |
8012 KB |
Output is correct |
15 |
Correct |
6 ms |
8012 KB |
Output is correct |
16 |
Correct |
6 ms |
8012 KB |
Output is correct |
17 |
Correct |
6 ms |
8012 KB |
Output is correct |
18 |
Correct |
6 ms |
8012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8092 KB |
Output is correct |
2 |
Correct |
6 ms |
8004 KB |
Output is correct |
3 |
Correct |
6 ms |
8112 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
6 ms |
8012 KB |
Output is correct |
6 |
Correct |
6 ms |
8012 KB |
Output is correct |
7 |
Correct |
6 ms |
8012 KB |
Output is correct |
8 |
Correct |
6 ms |
8012 KB |
Output is correct |
9 |
Correct |
6 ms |
8012 KB |
Output is correct |
10 |
Correct |
6 ms |
8012 KB |
Output is correct |
11 |
Correct |
6 ms |
8012 KB |
Output is correct |
12 |
Correct |
6 ms |
8012 KB |
Output is correct |
13 |
Correct |
6 ms |
8012 KB |
Output is correct |
14 |
Correct |
6 ms |
8012 KB |
Output is correct |
15 |
Correct |
6 ms |
8012 KB |
Output is correct |
16 |
Correct |
6 ms |
8012 KB |
Output is correct |
17 |
Correct |
6 ms |
8012 KB |
Output is correct |
18 |
Correct |
6 ms |
8012 KB |
Output is correct |
19 |
Correct |
7 ms |
8040 KB |
Output is correct |
20 |
Correct |
6 ms |
8012 KB |
Output is correct |
21 |
Correct |
6 ms |
8012 KB |
Output is correct |
22 |
Correct |
7 ms |
8032 KB |
Output is correct |
23 |
Correct |
7 ms |
8124 KB |
Output is correct |
24 |
Correct |
8 ms |
8012 KB |
Output is correct |
25 |
Correct |
8 ms |
8076 KB |
Output is correct |
26 |
Correct |
6 ms |
8012 KB |
Output is correct |
27 |
Correct |
6 ms |
8012 KB |
Output is correct |
28 |
Correct |
6 ms |
8016 KB |
Output is correct |
29 |
Correct |
6 ms |
8012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8092 KB |
Output is correct |
2 |
Correct |
6 ms |
8004 KB |
Output is correct |
3 |
Correct |
6 ms |
8112 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
6 ms |
8012 KB |
Output is correct |
6 |
Correct |
6 ms |
8012 KB |
Output is correct |
7 |
Correct |
6 ms |
8012 KB |
Output is correct |
8 |
Correct |
6 ms |
8012 KB |
Output is correct |
9 |
Correct |
6 ms |
8012 KB |
Output is correct |
10 |
Correct |
6 ms |
8012 KB |
Output is correct |
11 |
Correct |
6 ms |
8012 KB |
Output is correct |
12 |
Correct |
6 ms |
8012 KB |
Output is correct |
13 |
Correct |
6 ms |
8012 KB |
Output is correct |
14 |
Correct |
6 ms |
8012 KB |
Output is correct |
15 |
Correct |
6 ms |
8012 KB |
Output is correct |
16 |
Correct |
6 ms |
8012 KB |
Output is correct |
17 |
Correct |
6 ms |
8012 KB |
Output is correct |
18 |
Correct |
6 ms |
8012 KB |
Output is correct |
19 |
Correct |
7 ms |
8040 KB |
Output is correct |
20 |
Correct |
6 ms |
8012 KB |
Output is correct |
21 |
Correct |
6 ms |
8012 KB |
Output is correct |
22 |
Correct |
7 ms |
8032 KB |
Output is correct |
23 |
Correct |
7 ms |
8124 KB |
Output is correct |
24 |
Correct |
8 ms |
8012 KB |
Output is correct |
25 |
Correct |
8 ms |
8076 KB |
Output is correct |
26 |
Correct |
6 ms |
8012 KB |
Output is correct |
27 |
Correct |
6 ms |
8012 KB |
Output is correct |
28 |
Correct |
6 ms |
8016 KB |
Output is correct |
29 |
Correct |
6 ms |
8012 KB |
Output is correct |
30 |
Correct |
169 ms |
15872 KB |
Output is correct |
31 |
Correct |
163 ms |
16580 KB |
Output is correct |
32 |
Correct |
146 ms |
16508 KB |
Output is correct |
33 |
Correct |
148 ms |
16520 KB |
Output is correct |
34 |
Correct |
153 ms |
16512 KB |
Output is correct |
35 |
Correct |
149 ms |
16472 KB |
Output is correct |
36 |
Correct |
147 ms |
16520 KB |
Output is correct |
37 |
Correct |
146 ms |
16496 KB |
Output is correct |
38 |
Correct |
149 ms |
16504 KB |
Output is correct |
39 |
Correct |
160 ms |
16500 KB |
Output is correct |
40 |
Correct |
146 ms |
16516 KB |
Output is correct |
41 |
Correct |
154 ms |
16516 KB |
Output is correct |
42 |
Correct |
147 ms |
16508 KB |
Output is correct |
43 |
Correct |
145 ms |
16468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
8012 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '3594' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8092 KB |
Output is correct |
2 |
Correct |
6 ms |
8004 KB |
Output is correct |
3 |
Correct |
6 ms |
8112 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
6 ms |
8012 KB |
Output is correct |
6 |
Correct |
6 ms |
8012 KB |
Output is correct |
7 |
Correct |
6 ms |
8012 KB |
Output is correct |
8 |
Correct |
6 ms |
8012 KB |
Output is correct |
9 |
Correct |
6 ms |
8012 KB |
Output is correct |
10 |
Correct |
6 ms |
8012 KB |
Output is correct |
11 |
Correct |
6 ms |
8012 KB |
Output is correct |
12 |
Correct |
6 ms |
8012 KB |
Output is correct |
13 |
Correct |
6 ms |
8012 KB |
Output is correct |
14 |
Correct |
6 ms |
8012 KB |
Output is correct |
15 |
Correct |
6 ms |
8012 KB |
Output is correct |
16 |
Correct |
6 ms |
8012 KB |
Output is correct |
17 |
Correct |
6 ms |
8012 KB |
Output is correct |
18 |
Correct |
6 ms |
8012 KB |
Output is correct |
19 |
Correct |
7 ms |
8040 KB |
Output is correct |
20 |
Correct |
6 ms |
8012 KB |
Output is correct |
21 |
Correct |
6 ms |
8012 KB |
Output is correct |
22 |
Correct |
7 ms |
8032 KB |
Output is correct |
23 |
Correct |
7 ms |
8124 KB |
Output is correct |
24 |
Correct |
8 ms |
8012 KB |
Output is correct |
25 |
Correct |
8 ms |
8076 KB |
Output is correct |
26 |
Correct |
6 ms |
8012 KB |
Output is correct |
27 |
Correct |
6 ms |
8012 KB |
Output is correct |
28 |
Correct |
6 ms |
8016 KB |
Output is correct |
29 |
Correct |
6 ms |
8012 KB |
Output is correct |
30 |
Correct |
169 ms |
15872 KB |
Output is correct |
31 |
Correct |
163 ms |
16580 KB |
Output is correct |
32 |
Correct |
146 ms |
16508 KB |
Output is correct |
33 |
Correct |
148 ms |
16520 KB |
Output is correct |
34 |
Correct |
153 ms |
16512 KB |
Output is correct |
35 |
Correct |
149 ms |
16472 KB |
Output is correct |
36 |
Correct |
147 ms |
16520 KB |
Output is correct |
37 |
Correct |
146 ms |
16496 KB |
Output is correct |
38 |
Correct |
149 ms |
16504 KB |
Output is correct |
39 |
Correct |
160 ms |
16500 KB |
Output is correct |
40 |
Correct |
146 ms |
16516 KB |
Output is correct |
41 |
Correct |
154 ms |
16516 KB |
Output is correct |
42 |
Correct |
147 ms |
16508 KB |
Output is correct |
43 |
Correct |
145 ms |
16468 KB |
Output is correct |
44 |
Incorrect |
6 ms |
8012 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '3594' |
45 |
Halted |
0 ms |
0 KB |
- |