#include "books.h"
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL LINF = 1e18;
int a[10],n;
vector<int>vec;
bool check(){
bool q = 1;
for(int i=0;i<n;i++)
q &= (a[i]==vec[i]);
return q;
}
LL bt(int pos,int cur,int cnt);
LL move(int pos,int cur,int cnt){
LL ret = LINF;
if(pos<n-1)
ret = min(ret,bt(pos+1,cur,cnt+1));
if(pos>0)
ret = min(ret,bt(pos-1,cur,cnt+1));
return ret;
}
LL bt(int pos,int cur,int cnt){
if(!pos&&check())
return cnt;
if(cnt>10)
return LINF;
LL ret = LINF;
ret = min(ret,move(pos,cur,cnt));
swap(cur,a[pos]);
ret = min(ret,move(pos,cur,cnt));
swap(cur,a[pos]);
return ret;
}
long long minimum_walk(std::vector<int> P, int s) {
vec = P;
n = P.size();
for(int i=0;i<n;i++)
a[i] = i;
LL ans = bt(0,-1,0);
if(ans==10)
return 8;
}
Compilation message
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:64:1: warning: control reaches end of non-void function [-Wreturn-type]
64 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
44 ms |
292 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
204 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
2 |
Halted |
0 ms |
0 KB |
- |