#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
int where[nmax];
bool been[nmax];
long long minimum_walk(vector<int> p, int s)
{
int n=p.size();
for(int i=0;i<n;i++)
where[i]=p[i];
long long ans=0;
int last=0;
for(int i=0;i<n;i++)
if(been[i]==0)
{
ans=ans+i-last;
last=i;
int now=i;
while(been[now]==0)
{
ans=ans+abs(now-where[now]);
been[now]=1;
now=where[now];
}
}
return ans+last;
}
/*
int main()
{
cout<<minimum_walk({0, 2, 3, 1}, 0)<<endl;
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
3 ms |
356 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
3 ms |
356 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
3 ms |
356 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
560 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '4736' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
3 ms |
356 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |