#include "books.h"
#include<bits/stdc++.h>
using namespace std;
#define sz(v) ((int)(v).size())
typedef long long lint;
typedef pair<int,int> pii;
lint minimum_walk(vector<int> p, int s) {
int n=sz(p);
lint ans=0;
vector<int>v(n);
int m=0,step=0,end=0;
for(int i=0;i<n;i++)
{
if(!v[i])
{
int x=i;
v[i]=1;
m=i;
while(p[x]!=i)
{
v[p[x]]=1;
m=max(m,p[x]);
x=p[x];
}
ans+=2*(m-i);
if(m!=i)
{
if(end<i)step+=(i-end);
if(end<m)end=m;
}
}
}
ans+=2*step;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
296 KB |
3rd lines differ - on the 1st token, expected: '8', found: '6' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
296 KB |
3rd lines differ - on the 1st token, expected: '8', found: '6' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
296 KB |
3rd lines differ - on the 1st token, expected: '8', found: '6' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
308 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2720' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
296 KB |
3rd lines differ - on the 1st token, expected: '8', found: '6' |
4 |
Halted |
0 ms |
0 KB |
- |