#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;
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 |
Incorrect |
34 ms |
364 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
364 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
364 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2069 ms |
364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
364 KB |
3rd lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |