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;
const int N = 1e6 + 10;
int a[N] , n;
bool marked[N];
long long minimum_walk(vector<int> p, int s) {
n = p.size();
int ans = 0 , cnt = (p[0] == 0 ? 0 : 1);
marked[p[0]] = true;
for(int i = 1 ; i < n ; i++)
{
ans += max(2 * cnt , 2);
cnt++;
marked[p[i]] = true;
if(marked[i])
cnt--;
}
for(int i = n - 1 ; i >= 0 ; i--)
{
if(p[i] != i)
break;
ans -= 2;
}
return ans;
}
# | 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... |