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"
using namespace std;
using ll = long long;
constexpr ll INF = 1000000000000000000LL;
ll n, m, q, k, x, y, a, b, c;
map< pair< vector<int>, pair<int, int> >, ll > mp;
vector<int> perfect;
long long minimum_walk(vector<int> p, int s) {
ll num = 0;
bool fl = 1;
for (int i = 0; i < p.size(); i++) {
num += abs(i - p[i]);
if (i != p[i]) {
fl = 0;
}
if (fl) {
num += 2;
}
}
if (fl) {
num = 0;
}
return num;
// for (int i = 0; i < p.size(); i++) {
// perfect.push_back(i);
// }
// deque< pair< vector<int>, pair<int, int> > > q;
// q.push_back({p, {s, -1}});
// mp[{p, {s, -1}}] = 0;
// while (!q.empty()) {
// auto [p, p2] = q[0];
// auto [s, carry] = p2;
// q.pop_front();
// // for (auto i : p) {
// // cout << i << ' ';
// // }
// // cout << endl;
// // cout << s << ' ' << carry << endl;
// if (p == perfect && s == 0 && carry == -1) {
// return mp[{p, {s, carry}}];
// }
// ll d = mp[{p, {s, carry}}];
// swap(carry, p[s]);
// if (!mp.count({p, {s, carry}})) {
// q.push_front({p, {s, carry}});
// mp[{p, {s, carry}}] = d;
// }
// swap(carry, p[s]);
// if (s > 0 && !mp.count({p, {s - 1, carry}})) {
// q.push_back({p, {s - 1, carry}});
// mp[{p, {s - 1, carry}}] = d + 1;
// }
// if (s < p.size() - 1 && !mp.count({p, {s + 1, carry}})) {
// q.push_back({p, {s + 1, carry}});
// mp[{p, {s + 1, carry}}] = d + 1;
// }
// }
}
Compilation message (stderr)
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < p.size(); 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... |