#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N ((int)1001*1000)
int n;
ll prt[N],ans;
ll minimum_walk(vector<int> p, int s)
{
n=p.size();
int mini=s,maxi=s-1;
int mini2=s,maxi2=s-1;
for(int i=0;i<n;i++)
{
int l=min(i,p[i]),r=max(i,p[i]);
if(r<=s)
{
if(l!=r)mini=min(mini,l);
prt[(r>0)?r-1:N-1]++;
prt[(l>0)?l-1:N-1]--;
}
else if(l>=s)
{
if(l!=r)maxi=max(maxi,r-1);
prt[l]++;
prt[r]--;
}
else
{
maxi2=max(maxi2,r-1);
mini2=min(mini2,l);
prt[s]++;prt[r]--;
prt[(s>0)?s-1:N-1]++;
prt[(l>0)?l-1:N-1]--;
}
}
for(int i=s;i<n;i++)
{
if(i>s)prt[i]+=prt[i-1];
ans+=prt[i];
}
for(int i=s-1;i>=0;i--)
{
if(i!=s-1)prt[i]+=prt[i+1];
ans+=prt[i];
}
// cout<<mini<<" "<<mini2<<" "<<maxi<<" "<<maxi2<<"\n";
ll res=0;
for(int i=s;i<=max(maxi2,maxi);i++)if(!prt[i])res+=2;
for(int i=s-1;i>=mini;i--)if(!prt[i])res+=2;
ll res2=0;
for(int i=s;i<=maxi;i++)if(!prt[i])res2+=2;
for(int i=s-1;i>=min(mini2,mini);i--)if(!prt[i])res2+=2;
// cout<<ans<<"\n";
ans+=min(res,res2);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
432 KB |
Output is correct |
5 |
Correct |
5 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
764 KB |
Output is correct |
7 |
Correct |
3 ms |
764 KB |
Output is correct |
8 |
Correct |
3 ms |
764 KB |
Output is correct |
9 |
Correct |
4 ms |
764 KB |
Output is correct |
10 |
Correct |
3 ms |
764 KB |
Output is correct |
11 |
Correct |
3 ms |
764 KB |
Output is correct |
12 |
Correct |
4 ms |
764 KB |
Output is correct |
13 |
Correct |
3 ms |
764 KB |
Output is correct |
14 |
Correct |
3 ms |
764 KB |
Output is correct |
15 |
Correct |
3 ms |
764 KB |
Output is correct |
16 |
Correct |
2 ms |
764 KB |
Output is correct |
17 |
Correct |
4 ms |
764 KB |
Output is correct |
18 |
Correct |
3 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
432 KB |
Output is correct |
5 |
Correct |
5 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
764 KB |
Output is correct |
7 |
Correct |
3 ms |
764 KB |
Output is correct |
8 |
Correct |
3 ms |
764 KB |
Output is correct |
9 |
Correct |
4 ms |
764 KB |
Output is correct |
10 |
Correct |
3 ms |
764 KB |
Output is correct |
11 |
Correct |
3 ms |
764 KB |
Output is correct |
12 |
Correct |
4 ms |
764 KB |
Output is correct |
13 |
Correct |
3 ms |
764 KB |
Output is correct |
14 |
Correct |
3 ms |
764 KB |
Output is correct |
15 |
Correct |
3 ms |
764 KB |
Output is correct |
16 |
Correct |
2 ms |
764 KB |
Output is correct |
17 |
Correct |
4 ms |
764 KB |
Output is correct |
18 |
Correct |
3 ms |
764 KB |
Output is correct |
19 |
Correct |
3 ms |
764 KB |
Output is correct |
20 |
Correct |
4 ms |
764 KB |
Output is correct |
21 |
Correct |
3 ms |
764 KB |
Output is correct |
22 |
Correct |
3 ms |
764 KB |
Output is correct |
23 |
Correct |
4 ms |
764 KB |
Output is correct |
24 |
Correct |
2 ms |
764 KB |
Output is correct |
25 |
Correct |
3 ms |
764 KB |
Output is correct |
26 |
Correct |
4 ms |
764 KB |
Output is correct |
27 |
Correct |
4 ms |
764 KB |
Output is correct |
28 |
Correct |
4 ms |
764 KB |
Output is correct |
29 |
Correct |
3 ms |
764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
432 KB |
Output is correct |
5 |
Correct |
5 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
764 KB |
Output is correct |
7 |
Correct |
3 ms |
764 KB |
Output is correct |
8 |
Correct |
3 ms |
764 KB |
Output is correct |
9 |
Correct |
4 ms |
764 KB |
Output is correct |
10 |
Correct |
3 ms |
764 KB |
Output is correct |
11 |
Correct |
3 ms |
764 KB |
Output is correct |
12 |
Correct |
4 ms |
764 KB |
Output is correct |
13 |
Correct |
3 ms |
764 KB |
Output is correct |
14 |
Correct |
3 ms |
764 KB |
Output is correct |
15 |
Correct |
3 ms |
764 KB |
Output is correct |
16 |
Correct |
2 ms |
764 KB |
Output is correct |
17 |
Correct |
4 ms |
764 KB |
Output is correct |
18 |
Correct |
3 ms |
764 KB |
Output is correct |
19 |
Correct |
3 ms |
764 KB |
Output is correct |
20 |
Correct |
4 ms |
764 KB |
Output is correct |
21 |
Correct |
3 ms |
764 KB |
Output is correct |
22 |
Correct |
3 ms |
764 KB |
Output is correct |
23 |
Correct |
4 ms |
764 KB |
Output is correct |
24 |
Correct |
2 ms |
764 KB |
Output is correct |
25 |
Correct |
3 ms |
764 KB |
Output is correct |
26 |
Correct |
4 ms |
764 KB |
Output is correct |
27 |
Correct |
4 ms |
764 KB |
Output is correct |
28 |
Correct |
4 ms |
764 KB |
Output is correct |
29 |
Correct |
3 ms |
764 KB |
Output is correct |
30 |
Correct |
328 ms |
16236 KB |
Output is correct |
31 |
Correct |
336 ms |
16236 KB |
Output is correct |
32 |
Correct |
254 ms |
16236 KB |
Output is correct |
33 |
Correct |
213 ms |
16236 KB |
Output is correct |
34 |
Correct |
220 ms |
16316 KB |
Output is correct |
35 |
Correct |
223 ms |
16316 KB |
Output is correct |
36 |
Correct |
232 ms |
16316 KB |
Output is correct |
37 |
Correct |
302 ms |
16316 KB |
Output is correct |
38 |
Correct |
319 ms |
16316 KB |
Output is correct |
39 |
Correct |
217 ms |
16316 KB |
Output is correct |
40 |
Correct |
271 ms |
16316 KB |
Output is correct |
41 |
Correct |
251 ms |
16316 KB |
Output is correct |
42 |
Correct |
254 ms |
16316 KB |
Output is correct |
43 |
Correct |
222 ms |
16316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
16316 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 |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
432 KB |
Output is correct |
4 |
Correct |
2 ms |
432 KB |
Output is correct |
5 |
Correct |
5 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
764 KB |
Output is correct |
7 |
Correct |
3 ms |
764 KB |
Output is correct |
8 |
Correct |
3 ms |
764 KB |
Output is correct |
9 |
Correct |
4 ms |
764 KB |
Output is correct |
10 |
Correct |
3 ms |
764 KB |
Output is correct |
11 |
Correct |
3 ms |
764 KB |
Output is correct |
12 |
Correct |
4 ms |
764 KB |
Output is correct |
13 |
Correct |
3 ms |
764 KB |
Output is correct |
14 |
Correct |
3 ms |
764 KB |
Output is correct |
15 |
Correct |
3 ms |
764 KB |
Output is correct |
16 |
Correct |
2 ms |
764 KB |
Output is correct |
17 |
Correct |
4 ms |
764 KB |
Output is correct |
18 |
Correct |
3 ms |
764 KB |
Output is correct |
19 |
Correct |
3 ms |
764 KB |
Output is correct |
20 |
Correct |
4 ms |
764 KB |
Output is correct |
21 |
Correct |
3 ms |
764 KB |
Output is correct |
22 |
Correct |
3 ms |
764 KB |
Output is correct |
23 |
Correct |
4 ms |
764 KB |
Output is correct |
24 |
Correct |
2 ms |
764 KB |
Output is correct |
25 |
Correct |
3 ms |
764 KB |
Output is correct |
26 |
Correct |
4 ms |
764 KB |
Output is correct |
27 |
Correct |
4 ms |
764 KB |
Output is correct |
28 |
Correct |
4 ms |
764 KB |
Output is correct |
29 |
Correct |
3 ms |
764 KB |
Output is correct |
30 |
Correct |
328 ms |
16236 KB |
Output is correct |
31 |
Correct |
336 ms |
16236 KB |
Output is correct |
32 |
Correct |
254 ms |
16236 KB |
Output is correct |
33 |
Correct |
213 ms |
16236 KB |
Output is correct |
34 |
Correct |
220 ms |
16316 KB |
Output is correct |
35 |
Correct |
223 ms |
16316 KB |
Output is correct |
36 |
Correct |
232 ms |
16316 KB |
Output is correct |
37 |
Correct |
302 ms |
16316 KB |
Output is correct |
38 |
Correct |
319 ms |
16316 KB |
Output is correct |
39 |
Correct |
217 ms |
16316 KB |
Output is correct |
40 |
Correct |
271 ms |
16316 KB |
Output is correct |
41 |
Correct |
251 ms |
16316 KB |
Output is correct |
42 |
Correct |
254 ms |
16316 KB |
Output is correct |
43 |
Correct |
222 ms |
16316 KB |
Output is correct |
44 |
Incorrect |
3 ms |
16316 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
45 |
Halted |
0 ms |
0 KB |
- |