Submission #1053550

#TimeUsernameProblemLanguageResultExecution timeMemory
1053550UnforgettableplAncient Books (IOI17_books)C++17
0 / 100
2033 ms436 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; const int THRESHOLD = 13; long long minimum_walk(vector<int> p, int s) { int n = p.size(); vector<int> res(n,-1); for(int i=0;i<n;i++)res[p[i]]=i; long long ans = 1e10; vector<int> curr(n);iota(curr.begin(), curr.end(),0); int currhand = 0; curr[0]=-1; function<void(int,long long,int)> calc = [&](int x,long long t,int moves) { if(moves>THRESHOLD)return; swap(currhand,curr[x]); if(curr==res) { ans = min(ans,t+x); return; } for(int i=0;i<n;i++)if(i!=x) { calc(i,t+abs(x-i),moves+1); } swap(currhand,curr[x]); }; calc(0,0,0); return ans; }
#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...