#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
long long minimum_walk(std::vector<int> p, int s)
{
int n=p.size();
ll ans=0;
int mex_low=0;
int mex_high=n-1;
vector <bool> v(1000007,0);
int left_limit=0;
int right_limit=n-1;
for(int i=0;i<=s;i++)
{
ans+=abs(i-p[i]);
v[p[i]]=1;
while(v[mex_low]==1)
{
mex_low++;
}
if(mex_low>i)
{
if(i!=s)
ans+=2;
left_limit=i+1;
}
}
v=vector <bool> (1000007,0);
for(int i=n-1;i>=s;i--)
{
ans+=abs(i-p[i]);
v[p[i]]=1;
while(mex_high>=0 && v[mex_high]==1)
{
mex_high--;
}
if(mex_high<i)
{
if(i!=s)
ans+=2;
right_limit=i-1;
}
}
ans-=abs(s-p[s]);
int lptr=s;
int rptr=s;
v=vector <bool> (1000007,0);
mex_low=s;
mex_high=s;
int mini=p[s];
int maxi=p[s];
v[p[s]]=1;
while(lptr>=left_limit && rptr<=right_limit)
{
while(mini<lptr || rptr<maxi)
{
while(mini<lptr)
{
lptr--;
v[p[lptr]]=1;
mini=min(mini,p[lptr]);
maxi=max(maxi,p[lptr]);
}
while(rptr<maxi)
{
rptr++;
v[p[rptr]]=1;
mini=min(mini,p[rptr]);
maxi=max(maxi,p[rptr]);
}
}
while(mex_low>=0 && v[mex_low]==1)
{
mex_low--;
}
while(v[mex_high]==1)
{
mex_high++;
}
if(lptr==left_limit && rptr==right_limit)
{
break;
}
ans+=2;
mini--;
maxi++;
}
/*if(left_limit>right_limit)
{
ans-=2;
}*/
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Incorrect |
0 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Incorrect |
0 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Incorrect |
0 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Incorrect |
1 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '5920', found: '5922' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Incorrect |
0 ms |
468 KB |
3rd lines differ - on the 1st token, expected: '4', found: '6' |
6 |
Halted |
0 ms |
0 KB |
- |