Submission #821288

#TimeUsernameProblemLanguageResultExecution timeMemory
821288vjudge1Ancient Books (IOI17_books)C++14
12 / 100
74 ms284 KiB
#include<bits/stdc++.h> #include "books.h" #define fi first #define se second #define ll long long using namespace std ; ll ans = 1e18 ; int sz ; vector<int> now ; bool check() { vector<int> gr = now ; sort(gr.begin(), gr.end()) ; return (now == gr) ; } void rec(int ind, int cnt, int sum, int with) { if(with == -1 && check()) { ans = min(ans, (ll)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<int> p, int s) { sz = p.size() ; if(sz <= 4) { now = p ; rec(s, 0ll, 0ll, -1ll) ; } return ans ; } //signed main() //{ // int n, s ; // cin >> n >> s ; // vector<int> p(n) ; // for(int i = 0 ; i < n ; i++) // cin >> p[i] ; // cout << minimum_walk(p, s) ; // return 0 ; //}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...