#include<bits/stdc++.h>
using namespace std;
#define _ int v, int tl, int tr, int l, int r
#define tm (tl+tr >> 1)
#define sol v+v,tl,tm,l,r
#define sag v+v+1,tm+1,tr,l,r
#define mp make_pair
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef pair < ll , ll > pp;
const int mod = 1e9 + 7;
const int N = 1e6 + 6;
ll H[N],A[N],n,i,l,r,t,x;
ll minimum_walk(vector < int > p , int s){
memset(H , 0 , sizeof H);
x = t = 0;
n = p.size();
for(i=0;i<n;i++){
x += abs(p[i] - i);
if(H[i]) continue;
l = r = i;
for(x=i; !H[x] ; x = p[x]){
H[x] = 1;
l = min(l , i);
r = max(r , i);
}
A[l] = r;
}
for(r=-1,i=0;i<n;i++){
if(i > r) t++;
r = max(r , A[i]);
}
return x + (t-1)*2;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8056 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8056 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8056 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
8292 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '3995' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8056 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
2 |
Halted |
0 ms |
0 KB |
- |