This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define append push_back
#define add insert
#define nl '\n'
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) (x).begin(),(x).end()
#define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define terminator main
#define MAXN 1000000
int vis[MAXN];
ll minimum_walk(vector<int> v,int s){
ll o=0;
int n,m,p,q;
n=v.size();
for(int i=0;i<n;i++) vis[i]=0;
for(int i=p=q=0;i<n;i++){
if(v[i]!=i && !vis[i] && q<i)
p=i;
m=i;
while(!vis[m]){
o+=abs(v[m]-m);
q=max(q,m);
vis[m]=1;
m=v[m];
}
}
return o+2*p;
}
# | 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... |