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 <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=1e6+5;
int vs[nx], n, lst, dp[nx];
ll res;
long long minimum_walk(std::vector<int> p, int s) {
n=p.size();
for (int i=0; i<n; i++)
{
res+=abs(i-p[i]);
dp[min(i, p[i])]++;
dp[max(i, p[i])]--;
}
for (int i=1; i<n; i++) dp[i]+=dp[i-1];
for (int i=n-1; i>=0; i--)
{
if (dp[i]) break;
dp[i]=1;
}
for (int i=0; i<n-1; i++) if (dp[i]==0) res+=2;
return res;
}
# | 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... |