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>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
long long minimum_walk(vector<int> p, int s) {
ll ans = 0;
ll prev = s;
int cur = -1;
ll lo=0, hi=p.size()-1;
while (lo < hi){
while (p[lo] == lo && lo < hi){
lo++;
}
while (p[hi] == hi && lo < hi){
hi--;
}
if (!(lo<hi)) break;
ans += abs(prev-lo);
prev = lo;
FOR(i,lo,hi+1){
if (p[i] > cur){
swap(p[i], cur);
}else if (cur == i){
swap(p[i],cur);
}
}
ans += (hi-lo);
FORNEG(i, hi, lo-1){
if (p[i] < cur){
swap(p[i], cur);
}else if (cur == i){
swap(p[i],cur);
}
}
ans += (hi-lo);
}
ans += abs(0-prev);
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... |