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"
#include<bits/stdc++.h>
using namespace std;
set<tuple<vector<int>, int, int, int>> dp;
int ans = 1<<30, os;
void solve(vector<int> p, int s, int hand, int cur) {
if(cur > 30) return;
if(!dp.insert({p, s, hand, cur}).second) return;
int ok = 1;
for(int i = 0; i < p.size(); i++) ok &= p[i] == i;
if(ok&&s==os) ans = min(ans, cur);
if(s+1 < p.size()) solve(p, s+1, hand, cur+1);
if(s) solve(p, s-1, hand, cur+1);
swap(p[s], hand);
solve(p, s, hand, cur);
}
long long minimum_walk(std::vector<int> p, int s) {
os = s;
solve(p, s, -1, 0);
return ans;
}
Compilation message (stderr)
books.cpp: In function 'void solve(std::vector<int>, int, int, int)':
books.cpp:10:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < p.size(); i++) ok &= p[i] == i;
~~^~~~~~~~~~
books.cpp:12:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(s+1 < p.size()) solve(p, s+1, hand, cur+1);
~~~~^~~~~~~~~~
# | 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... |