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 int long long
long long minimum_walk(std::vector<int32_t> p, int32_t s) {
// return 0;
while(p.size() && p.back() == (int) p.size()-1) p.pop_back();
if(p.size() == 0) return 0;
int n = p.size();
int ans = 0;
int max_reach = -1;
for(int i = 0; i < n; i++) {
ans+= abs(p[i]-i);
if(i != 0 && max_reach < i) ans+= 2;
max_reach = max(max_reach,(int) p[i]);
}
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... |