#include "books.h"
#ifndef EVAL
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
const int N = 1e6+5;
bool bad[N];
int n, a[N], pos[N];
ll calc(int now, int carry, int lvl=0, int got=0){
if(lvl > 15)return 1e9;
lvl++;
bool ok = true;
for(int i=0;i<n;i++){
if(a[i] != i)ok=false;
}if(ok)return got + now;
ll res = 1e9;
swap(a[now], carry);
res = min(res, calc(now, carry, lvl, got));
swap(a[now], carry);
if(now+1 < n)res = min(res, calc(now+1, carry, lvl, got+1));
if(now > 0)res = min(res, calc(now-1, carry, lvl, got+1));
return res;
}
ll minimum_walk(vector<int> p, int s) {
n = p.size();
for(int i=0;i<n;i++){
a[i] = p[i];
}
return calc(s, -1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
364 KB |
Output is correct |
2 |
Correct |
34 ms |
364 KB |
Output is correct |
3 |
Correct |
39 ms |
364 KB |
Output is correct |
4 |
Correct |
11 ms |
364 KB |
Output is correct |
5 |
Correct |
34 ms |
364 KB |
Output is correct |
6 |
Correct |
36 ms |
396 KB |
Output is correct |
7 |
Correct |
34 ms |
364 KB |
Output is correct |
8 |
Correct |
41 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
32 ms |
492 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
34 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
34 ms |
364 KB |
Output is correct |
16 |
Correct |
34 ms |
364 KB |
Output is correct |
17 |
Correct |
38 ms |
364 KB |
Output is correct |
18 |
Correct |
34 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
364 KB |
Output is correct |
2 |
Correct |
34 ms |
364 KB |
Output is correct |
3 |
Correct |
39 ms |
364 KB |
Output is correct |
4 |
Correct |
11 ms |
364 KB |
Output is correct |
5 |
Correct |
34 ms |
364 KB |
Output is correct |
6 |
Correct |
36 ms |
396 KB |
Output is correct |
7 |
Correct |
34 ms |
364 KB |
Output is correct |
8 |
Correct |
41 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
32 ms |
492 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
34 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
34 ms |
364 KB |
Output is correct |
16 |
Correct |
34 ms |
364 KB |
Output is correct |
17 |
Correct |
38 ms |
364 KB |
Output is correct |
18 |
Correct |
34 ms |
364 KB |
Output is correct |
19 |
Execution timed out |
2071 ms |
384 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
364 KB |
Output is correct |
2 |
Correct |
34 ms |
364 KB |
Output is correct |
3 |
Correct |
39 ms |
364 KB |
Output is correct |
4 |
Correct |
11 ms |
364 KB |
Output is correct |
5 |
Correct |
34 ms |
364 KB |
Output is correct |
6 |
Correct |
36 ms |
396 KB |
Output is correct |
7 |
Correct |
34 ms |
364 KB |
Output is correct |
8 |
Correct |
41 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
32 ms |
492 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
34 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
34 ms |
364 KB |
Output is correct |
16 |
Correct |
34 ms |
364 KB |
Output is correct |
17 |
Correct |
38 ms |
364 KB |
Output is correct |
18 |
Correct |
34 ms |
364 KB |
Output is correct |
19 |
Execution timed out |
2071 ms |
384 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2087 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
364 KB |
Output is correct |
2 |
Correct |
34 ms |
364 KB |
Output is correct |
3 |
Correct |
39 ms |
364 KB |
Output is correct |
4 |
Correct |
11 ms |
364 KB |
Output is correct |
5 |
Correct |
34 ms |
364 KB |
Output is correct |
6 |
Correct |
36 ms |
396 KB |
Output is correct |
7 |
Correct |
34 ms |
364 KB |
Output is correct |
8 |
Correct |
41 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
32 ms |
492 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
34 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
34 ms |
364 KB |
Output is correct |
16 |
Correct |
34 ms |
364 KB |
Output is correct |
17 |
Correct |
38 ms |
364 KB |
Output is correct |
18 |
Correct |
34 ms |
364 KB |
Output is correct |
19 |
Execution timed out |
2071 ms |
384 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |