이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int n;
int l = 0;
int h = -1;
vi a;
int bst = INT_MAX;
bool correct()
{
bool r = true;
for (int i = 0; i < n; i++)
if (a[i] != i)
r = false;
return r;
}
void bk(int p, int d)
{
cout << d << endl;
if (p == 0 && correct()) {
bst = min(bst, l);
return;
}
if (l >= bst || d >= 10)
return;
for (int i = 0; i < n; i++) {
if (i == p)
continue;
l += abs(p - i);
swap(h, a[p]);
bk(i, d + 1);
swap(h, a[p]);
bk(i, d + 1);
l -= abs(p - i);
}
}
long long minimum_walk(vector<int> p, int s)
{
//cout << "HELLO" << endl;
n = p.size();
for (int x : p)
a.push_back(x);
bk(0, 0);
return bst;
}
# | 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... |