# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
775886 | peteza | Ancient Books (IOI17_books) | C++14 | 1541 ms | 1048576 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 <bits/stdc++.h>
#include "books.h"
struct state {
std::vector<int> cur;
int cpos, car;
};
long long minimum_walk(std::vector<int> p, int s) {
int cur = 0;
state start;
start.cur = p; start.cpos = s; start.car = -1;
std::queue<std::pair<int, state>> q;
q.emplace(0, start);
while(!q.empty()) {
auto e = q.front(); q.pop();
auto dat = e.second;
if(std::is_sorted(dat.cur.begin(), dat.cur.end()) && dat.cpos == s && dat.car == -1)
return e.first;
std::swap(dat.cur[dat.cpos], dat.car);
q.emplace(e.first, dat);
std::swap(dat.cur[dat.cpos], dat.car);
if(dat.cpos != 0) {
dat.cpos--;
q.emplace(e.first+1, dat);
dat.cpos++;
}
if(dat.cpos != p.size()-1) {
dat.cpos++;
q.emplace(e.first+1, dat);
dat.cpos--;
}
}
}
Compilation message (stderr)
# | 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... |