#include "books.h"
#include<bits/stdc++.h>
long long minimum_walk(std::vector<int> p, int s) {
int len=p.size();
long long ans=0;
int max=len-1;
int pos[len];
for(int i=0;i<len;i++)
{
pos[p[i]]=i;
}
while(pos[max]==max)
{
max=max-1;
if(max==0)
{
return ans;
}
}
int i=0;
int carrying=p[0];
//cout<<"aa"<<endl;
while(p[i]!=-1)
{
if(pos[max]==max)
{
max--;
continue;
}
ans=ans+abs(pos[max]-i);
p[pos[max]]=carrying;
pos[carrying]=pos[max];
if(i==0)
{
p[i]=-1;
}
else p[i]=carrying;
i=pos[max];
ans=ans+abs(max-i);
carrying=p[max];
i=max;
pos[i]=max;
max--;
//cout<<i<<" "<<p[i]<<endl;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2786' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |