#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
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 |
1 |
Correct |
6 ms |
1024 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
3 |
Correct |
6 ms |
1024 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
1024 KB |
Output is correct |
6 |
Correct |
6 ms |
1024 KB |
Output is correct |
7 |
Correct |
5 ms |
1024 KB |
Output is correct |
8 |
Correct |
5 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
1024 KB |
Output is correct |
10 |
Correct |
5 ms |
1024 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
6 ms |
1024 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
6 ms |
1024 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
7 ms |
1024 KB |
Output is correct |
18 |
Correct |
6 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1024 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
3 |
Correct |
6 ms |
1024 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
1024 KB |
Output is correct |
6 |
Correct |
6 ms |
1024 KB |
Output is correct |
7 |
Correct |
5 ms |
1024 KB |
Output is correct |
8 |
Correct |
5 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
1024 KB |
Output is correct |
10 |
Correct |
5 ms |
1024 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
6 ms |
1024 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
6 ms |
1024 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
7 ms |
1024 KB |
Output is correct |
18 |
Correct |
6 ms |
1024 KB |
Output is correct |
19 |
Execution timed out |
2116 ms |
574984 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1024 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
3 |
Correct |
6 ms |
1024 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
1024 KB |
Output is correct |
6 |
Correct |
6 ms |
1024 KB |
Output is correct |
7 |
Correct |
5 ms |
1024 KB |
Output is correct |
8 |
Correct |
5 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
1024 KB |
Output is correct |
10 |
Correct |
5 ms |
1024 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
6 ms |
1024 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
6 ms |
1024 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
7 ms |
1024 KB |
Output is correct |
18 |
Correct |
6 ms |
1024 KB |
Output is correct |
19 |
Execution timed out |
2116 ms |
574984 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2108 ms |
297284 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1024 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
3 |
Correct |
6 ms |
1024 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
6 ms |
1024 KB |
Output is correct |
6 |
Correct |
6 ms |
1024 KB |
Output is correct |
7 |
Correct |
5 ms |
1024 KB |
Output is correct |
8 |
Correct |
5 ms |
1024 KB |
Output is correct |
9 |
Correct |
6 ms |
1024 KB |
Output is correct |
10 |
Correct |
5 ms |
1024 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
6 ms |
1024 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
6 ms |
1024 KB |
Output is correct |
16 |
Correct |
5 ms |
1024 KB |
Output is correct |
17 |
Correct |
7 ms |
1024 KB |
Output is correct |
18 |
Correct |
6 ms |
1024 KB |
Output is correct |
19 |
Execution timed out |
2116 ms |
574984 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |