Submission #354930

#TimeUsernameProblemLanguageResultExecution timeMemory
354930tengiz05Ancient Books (IOI17_books)C++17
12 / 100
2087 ms492 KiB
#include "books.h" #ifndef EVAL #include "grader.cpp" #endif #include <bits/stdc++.h> using namespace std; typedef long long ll; #define pii pair<int,int> const int N = 1e6+5; bool bad[N]; int n, a[N], pos[N]; ll calc(int now, int carry, int lvl=0, int got=0){ if(lvl > 15)return 1e9; lvl++; bool ok = true; for(int i=0;i<n;i++){ if(a[i] != i)ok=false; }if(ok)return got + now; ll res = 1e9; swap(a[now], carry); res = min(res, calc(now, carry, lvl, got)); swap(a[now], carry); if(now+1 < n)res = min(res, calc(now+1, carry, lvl, got+1)); if(now > 0)res = min(res, calc(now-1, carry, lvl, got+1)); return res; } ll minimum_walk(vector<int> p, int s) { n = p.size(); for(int i=0;i<n;i++){ a[i] = p[i]; } return calc(s, -1); }
#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...