#include "books.h"
#include <bits/stdc++.h>
using namespace std;
const int THRESHOLD = 13;
long long minimum_walk(vector<int> p, int s) {
int n = p.size();
vector<int> res(n,-1);
for(int i=0;i<n;i++)res[p[i]]=i;
long long ans = 1e10;
vector<int> curr(n);iota(curr.begin(), curr.end(),0);
int currhand = 0;
curr[0]=-1;
function<void(int,long long,int)> calc = [&](int x,long long t,int moves) {
if(moves>THRESHOLD)return;
swap(currhand,curr[x]);
if(curr==res) {
ans = min(ans,t+x);
} else for(int i=0;i<n;i++)if(i!=x) {
calc(i,t+abs(x-i),moves+1);
}
swap(currhand,curr[x]);
};
calc(0,0,0);
swap(curr[0],currhand);
calc(0,0,0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
348 KB |
Output is correct |
2 |
Correct |
80 ms |
412 KB |
Output is correct |
3 |
Correct |
84 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
84 ms |
344 KB |
Output is correct |
6 |
Correct |
83 ms |
344 KB |
Output is correct |
7 |
Correct |
86 ms |
348 KB |
Output is correct |
8 |
Correct |
82 ms |
344 KB |
Output is correct |
9 |
Correct |
43 ms |
348 KB |
Output is correct |
10 |
Correct |
83 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
376 KB |
Output is correct |
13 |
Correct |
85 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
99 ms |
408 KB |
Output is correct |
16 |
Correct |
83 ms |
348 KB |
Output is correct |
17 |
Correct |
79 ms |
344 KB |
Output is correct |
18 |
Correct |
84 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
348 KB |
Output is correct |
2 |
Correct |
80 ms |
412 KB |
Output is correct |
3 |
Correct |
84 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
84 ms |
344 KB |
Output is correct |
6 |
Correct |
83 ms |
344 KB |
Output is correct |
7 |
Correct |
86 ms |
348 KB |
Output is correct |
8 |
Correct |
82 ms |
344 KB |
Output is correct |
9 |
Correct |
43 ms |
348 KB |
Output is correct |
10 |
Correct |
83 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
376 KB |
Output is correct |
13 |
Correct |
85 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
99 ms |
408 KB |
Output is correct |
16 |
Correct |
83 ms |
348 KB |
Output is correct |
17 |
Correct |
79 ms |
344 KB |
Output is correct |
18 |
Correct |
84 ms |
344 KB |
Output is correct |
19 |
Execution timed out |
2029 ms |
344 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
348 KB |
Output is correct |
2 |
Correct |
80 ms |
412 KB |
Output is correct |
3 |
Correct |
84 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
84 ms |
344 KB |
Output is correct |
6 |
Correct |
83 ms |
344 KB |
Output is correct |
7 |
Correct |
86 ms |
348 KB |
Output is correct |
8 |
Correct |
82 ms |
344 KB |
Output is correct |
9 |
Correct |
43 ms |
348 KB |
Output is correct |
10 |
Correct |
83 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
376 KB |
Output is correct |
13 |
Correct |
85 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
99 ms |
408 KB |
Output is correct |
16 |
Correct |
83 ms |
348 KB |
Output is correct |
17 |
Correct |
79 ms |
344 KB |
Output is correct |
18 |
Correct |
84 ms |
344 KB |
Output is correct |
19 |
Execution timed out |
2029 ms |
344 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2054 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
348 KB |
Output is correct |
2 |
Correct |
80 ms |
412 KB |
Output is correct |
3 |
Correct |
84 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
84 ms |
344 KB |
Output is correct |
6 |
Correct |
83 ms |
344 KB |
Output is correct |
7 |
Correct |
86 ms |
348 KB |
Output is correct |
8 |
Correct |
82 ms |
344 KB |
Output is correct |
9 |
Correct |
43 ms |
348 KB |
Output is correct |
10 |
Correct |
83 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
376 KB |
Output is correct |
13 |
Correct |
85 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
99 ms |
408 KB |
Output is correct |
16 |
Correct |
83 ms |
348 KB |
Output is correct |
17 |
Correct |
79 ms |
344 KB |
Output is correct |
18 |
Correct |
84 ms |
344 KB |
Output is correct |
19 |
Execution timed out |
2029 ms |
344 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |