#include <bits/stdc++.h>
#define ll long long
#define sz(x) int(x.size())
#define forn(i,n) for(i=0; i<n; i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fr first
#define se second
using namespace std;
long long minimum_walk(std::vector<int> p, int s) {
ll i, n=sz(p), ma=0, tot=0, pasos=0;
vector<ll>vis(n,0);
for(i=0; i<n; i++)
{
tot=tot+llabs(i-p[i]);
if(i<=ma)
vis[i]=1;
ma=max(ma,1ll*p[i]);
}
for(i=0; i<n; i++)
{
if(vis[i]==0)
pasos++;
else
{
tot=tot+2ll*pasos;
pasos=0;
}
}
return tot;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |