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;
using ll = long long;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
const ll MAXN = 1e6+100;
ll cnt[MAXN];
long long minimum_walk(std::vector<int> p, int s) {
ll n = sz(p);
for (ll i = 0;i < sz(p);i ++){
if (p[i] > i){
cnt[i]++,cnt[p[i]]--;
}
}
for (ll i = 1;i < n;i ++)cnt[i] += cnt[i-1];
int l = n + 1,r = -1;
ll res=0;
for (int i = 0;i < n;i ++){
if (cnt[i]){
res += cnt[i] * 2 - 2;
l = min(l,i);
r = max(r,i+1);
}
}
l = min(l,s);
r = max(r,s);
res += (r-l)*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... |