#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 res = s;
for(int i = 0 ; i < n ; i++){
if(ps[i] == 0) res = min(res , abs(i - s) - (i < s));
}
for(int i = l ; i <= r ; i++){
ans += max(2ll , ps[i]);
}
return ans + res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8012 KB |
Output is correct |
2 |
Correct |
6 ms |
8012 KB |
Output is correct |
3 |
Correct |
6 ms |
8084 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
6 ms |
8016 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 |
8016 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 |
7 ms |
8012 KB |
Output is correct |
17 |
Correct |
6 ms |
8012 KB |
Output is correct |
18 |
Correct |
6 ms |
8016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8012 KB |
Output is correct |
2 |
Correct |
6 ms |
8012 KB |
Output is correct |
3 |
Correct |
6 ms |
8084 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
6 ms |
8016 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 |
8016 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 |
7 ms |
8012 KB |
Output is correct |
17 |
Correct |
6 ms |
8012 KB |
Output is correct |
18 |
Correct |
6 ms |
8016 KB |
Output is correct |
19 |
Correct |
6 ms |
8012 KB |
Output is correct |
20 |
Correct |
6 ms |
8008 KB |
Output is correct |
21 |
Correct |
8 ms |
8060 KB |
Output is correct |
22 |
Correct |
6 ms |
8012 KB |
Output is correct |
23 |
Correct |
6 ms |
8012 KB |
Output is correct |
24 |
Correct |
7 ms |
8112 KB |
Output is correct |
25 |
Correct |
6 ms |
8012 KB |
Output is correct |
26 |
Correct |
6 ms |
8012 KB |
Output is correct |
27 |
Correct |
6 ms |
8012 KB |
Output is correct |
28 |
Correct |
8 ms |
8012 KB |
Output is correct |
29 |
Correct |
6 ms |
8012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8012 KB |
Output is correct |
2 |
Correct |
6 ms |
8012 KB |
Output is correct |
3 |
Correct |
6 ms |
8084 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
6 ms |
8016 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 |
8016 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 |
7 ms |
8012 KB |
Output is correct |
17 |
Correct |
6 ms |
8012 KB |
Output is correct |
18 |
Correct |
6 ms |
8016 KB |
Output is correct |
19 |
Correct |
6 ms |
8012 KB |
Output is correct |
20 |
Correct |
6 ms |
8008 KB |
Output is correct |
21 |
Correct |
8 ms |
8060 KB |
Output is correct |
22 |
Correct |
6 ms |
8012 KB |
Output is correct |
23 |
Correct |
6 ms |
8012 KB |
Output is correct |
24 |
Correct |
7 ms |
8112 KB |
Output is correct |
25 |
Correct |
6 ms |
8012 KB |
Output is correct |
26 |
Correct |
6 ms |
8012 KB |
Output is correct |
27 |
Correct |
6 ms |
8012 KB |
Output is correct |
28 |
Correct |
8 ms |
8012 KB |
Output is correct |
29 |
Correct |
6 ms |
8012 KB |
Output is correct |
30 |
Correct |
175 ms |
15856 KB |
Output is correct |
31 |
Correct |
162 ms |
15940 KB |
Output is correct |
32 |
Correct |
142 ms |
15872 KB |
Output is correct |
33 |
Correct |
163 ms |
15852 KB |
Output is correct |
34 |
Correct |
150 ms |
15868 KB |
Output is correct |
35 |
Correct |
175 ms |
15856 KB |
Output is correct |
36 |
Correct |
152 ms |
15868 KB |
Output is correct |
37 |
Correct |
146 ms |
15876 KB |
Output is correct |
38 |
Correct |
148 ms |
15864 KB |
Output is correct |
39 |
Correct |
152 ms |
15816 KB |
Output is correct |
40 |
Correct |
147 ms |
15856 KB |
Output is correct |
41 |
Correct |
151 ms |
15856 KB |
Output is correct |
42 |
Correct |
159 ms |
15860 KB |
Output is correct |
43 |
Correct |
151 ms |
15876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
8012 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '3169' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
8012 KB |
Output is correct |
2 |
Correct |
6 ms |
8012 KB |
Output is correct |
3 |
Correct |
6 ms |
8084 KB |
Output is correct |
4 |
Correct |
6 ms |
8012 KB |
Output is correct |
5 |
Correct |
6 ms |
8016 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 |
8016 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 |
7 ms |
8012 KB |
Output is correct |
17 |
Correct |
6 ms |
8012 KB |
Output is correct |
18 |
Correct |
6 ms |
8016 KB |
Output is correct |
19 |
Correct |
6 ms |
8012 KB |
Output is correct |
20 |
Correct |
6 ms |
8008 KB |
Output is correct |
21 |
Correct |
8 ms |
8060 KB |
Output is correct |
22 |
Correct |
6 ms |
8012 KB |
Output is correct |
23 |
Correct |
6 ms |
8012 KB |
Output is correct |
24 |
Correct |
7 ms |
8112 KB |
Output is correct |
25 |
Correct |
6 ms |
8012 KB |
Output is correct |
26 |
Correct |
6 ms |
8012 KB |
Output is correct |
27 |
Correct |
6 ms |
8012 KB |
Output is correct |
28 |
Correct |
8 ms |
8012 KB |
Output is correct |
29 |
Correct |
6 ms |
8012 KB |
Output is correct |
30 |
Correct |
175 ms |
15856 KB |
Output is correct |
31 |
Correct |
162 ms |
15940 KB |
Output is correct |
32 |
Correct |
142 ms |
15872 KB |
Output is correct |
33 |
Correct |
163 ms |
15852 KB |
Output is correct |
34 |
Correct |
150 ms |
15868 KB |
Output is correct |
35 |
Correct |
175 ms |
15856 KB |
Output is correct |
36 |
Correct |
152 ms |
15868 KB |
Output is correct |
37 |
Correct |
146 ms |
15876 KB |
Output is correct |
38 |
Correct |
148 ms |
15864 KB |
Output is correct |
39 |
Correct |
152 ms |
15816 KB |
Output is correct |
40 |
Correct |
147 ms |
15856 KB |
Output is correct |
41 |
Correct |
151 ms |
15856 KB |
Output is correct |
42 |
Correct |
159 ms |
15860 KB |
Output is correct |
43 |
Correct |
151 ms |
15876 KB |
Output is correct |
44 |
Incorrect |
6 ms |
8012 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '3169' |
45 |
Halted |
0 ms |
0 KB |
- |