#include "books.h"
#include<bits/stdc++.h>
using namespace std;
set<tuple<vector<int>, int, int>> dp;
int ans = 1<<30;
void solve(vector<int> p, int s, int cur) {
if(cur > 30) return;
if(!dp.insert({p, s, cur}).second) return;
int ok = 1;
for(int i = 0; i < p.size(); i++) ok &= p[i] == i;
if(ok&&s==0) ans = min(ans, cur);
for(int j = 0; j < p.size(); j++) if(j != s) {
swap(p[j], p[s]);
solve(p, j, cur+abs(s-j));
swap(p[j], p[s]);
}
}
long long minimum_walk(std::vector<int> p, int s) {
solve(p, s, 0);
return ans;
}
Compilation message
books.cpp: In function 'void solve(std::vector<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:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 0; j < p.size(); j++) if(j != s) {
~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '8', found: '1073741824' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '8', found: '1073741824' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '8', found: '1073741824' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2073 ms |
41720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Incorrect |
1 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '8', found: '1073741824' |
4 |
Halted |
0 ms |
0 KB |
- |