This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include"books.h"
#include <vector>
#include<bits/stdc++.h>
const int maxn=1000000+10;
using namespace std;
int vis[maxn],visa[maxn];
int n;
long long minimum_walk(std::vector<int> p, int s){
n=p.size();
long long mainres=0,last=0;
int cnt1=0;
for(int i=0;i<n;i++){
if(p[i]>i){
cnt1++;
visa[p[i]]=1;
}
if(visa[i]){
cnt1--;
}
mainres+=cnt1*2;
if(cnt1!=0){
last=i+1;
}
}
for(int i=0;i<=last;i++){
if(vis[i]==0){
mainres+=2;
int now=i;
do{
vis[now]=1;
now=p[now];
}while(now!=i);
}
}
mainres-=2;
return mainres;
}
# | 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... |