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 <bits/stdc++.h>
//~ #include "grader.cpp"
#include "books.h"
using namespace std;
#define ll long long
long long minimum_walk(std::vector<int> p, int s) {
int n = p.size();
vector <int> c(n);
ll ret = 0;
for(int i = 0 ; i < n ; i++){
ret += abs(i - p[i]);
int l = i, r = p[i];
if(l > r) swap(l, r);
c[l]++;
c[r]--;
}
for(int i = 1 ; i < n ; i++){
c[i] += c[i - 1];
}
int cur = 0;
for(int i = 0 ; i < n - 1 ; i++){
if(c[i] == 0) cur++;
else{
ret += 2 * cur;
cur = 0;
}
}
return ret;
}
# | 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... |