이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
const int N = 1e6+5;
bool bad[N];
int n, a[N], pos[N];
ll calc(int now, int carry, int lvl=0, int got=0){
if(lvl > 15)return 1e9;
lvl++;
bool ok = true;
for(int i=0;i<n;i++){
if(a[i] != i)ok=false;
}if(ok)return got + now;
ll res = 1e9;
swap(a[now], carry);
res = min(res, calc(now, carry, lvl, got));
swap(a[now], carry);
if(now+1 < n)res = min(res, calc(now+1, carry, lvl, got+1));
if(now > 0)res = min(res, calc(now-1, carry, lvl, got+1));
return res;
}
ll minimum_walk(vector<int> p, int s) {
n = p.size();
for(int i=0;i<n;i++){
a[i] = p[i];
}
return calc(s, -1);
}
| # | 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... |