| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 299713 | REALITYNB | Ancient Books (IOI17_books) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
//#define int long long
map<vector<int>,int> mem ;
int dp(vector<int> a , int i , int hand, int mv){
if(mv==20) return 1e7 ;
bool flg = 1 ;
for(int k=0;k<a.size();k++) if(k!=a[k]) flg = 0 ;
if(flg) return 0 ;
vector<int> mm= a ;
mm.push_back(i) ;
mm.push_back(mv) ;
mm.push_back(hand) ;
if(mem.count(mm)) return mem[mm] ;
int mn = 1e7 ;
//hand is empty
for(int j=0;j<a.size();j++){
swap(a[j],hand) ;
mn = min(mn,abs(i-j)+dp(a,j,hand,mv+1)) ;
swap(a[j],hand) ;
}
mem[mm]=mn ;
return mn ;
}
long long minimum_walk(vector<int> p , int s){
int n = p.size() ;
return dp(p,0,-1,0) ;
}
int main(){
cout <<minimum_walk({0, 2, 3, 1},0) ;
}
