# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
821278 | vjudge1 | Ancient Books (IOI17_books) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "prize.h"
#define fi first
#define se second
#define ll long long
using namespace std ;
ll ans = 1e18 ;
ll sz ;
vector<ll> now ;
bool check()
{
vector<ll> gr = now ;
sort(gr.begin(), gr.end()) ;
return (now == gr) ;
}
void rec(ll ind, ll cnt, ll sum, ll with)
{
// cout<<ind<<' '<<cnt << ' ' << with << '\n' ;
if(with == -1 && check())
{
ans = min(ans, sum + ind) ;
return ;
}
if(cnt == 16)
return ;
if(with != -1)
{
swap(now[ind], with) ;
rec(ind, cnt + 1, sum, with) ;
swap(now[ind], with) ;
}
else
{
if(now[ind] != -1)
{
swap(now[ind], with) ;
rec(ind, cnt + 1, sum, with) ;
swap(now[ind], with) ;
}
}
if(ind < sz - 1)
rec(ind + 1, cnt + 1, sum + 1, with) ;
if(ind)
rec(ind - 1, cnt + 1, sum + 1, with) ;
}
ll minimum_walk(vector<ll> p, ll s)
{
sz = p.size() ;
if(sz <= 4)
{
now = p ;
rec(s, 0, 0, -1) ;
}
return ans ;
}
//signed main()
//{
// ll n, s ;
// cin >> n >> s ;
// vector<ll> p(n) ;
// for(ll i = 0 ; i < n ; i++)
// cin >> p[i] ;
// cout << minimum_walk(p, s) ;
// return 0 ;
//}