이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |