# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
354930 | tengiz05 | Ancient Books (IOI17_books) | C++17 | 2087 ms | 492 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |