이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
const int nmax=1e6+42;
int go_left[nmax],go_right[nmax];
long long minimum_walk(std::vector<int> p, int s)
{
int n=p.size();
int maxi=0;
for(int i=0;i<n;i++)
if(i!=p[i])
{
maxi=max(maxi,i);
maxi=max(maxi,p[i]);
if(i<p[i])go_left[i]++,go_left[p[i]]--;
else go_right[p[i]]++,go_right[i]--;
}
for(int i=1;i<n;i++)
{
go_left[i]+=go_left[i-1];
go_right[i]+=go_right[i-1];
}
long long outp=0;
for(int i=0;i<maxi;i++)
{
//cout<<i<<" -> "<<go_left[i]<<" "<<go_right[i]<<endl;
if(go_left[i]==0&&go_right[i]==0)outp+=2;
else outp+=2*max(go_left[i],go_right[i]);
}
return outp;
}
# | 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... |