#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define F0R(i,b) FOR(i,0,b)
#define ROF(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define R0F(i,b) ROF(i,0,b)
#define all(x) begin(x),end(x)
#define pb push_back
#define trav(a,x) for(auto&a:x)
#define sz(x) int(x.size())
vi p;
int n;
ll ans=1e18;
bool ok(int now)
{
if(now!=0)return 0;
F0R(i,n)
{
if(p[i]!=i)return 0;
}
return 1;
}
void go(int now,int cur,ll d,int cnt)
{
if(now<0||now>=4)return;
if(cnt>6)return;
if(ok(now))
{
ans=min(ans,d);
}
FOR(i,-4,4+1)
{
go(now+i,cur,d+abs(i),cnt+1);
}
swap(cur,p[now]);
FOR(i,-4,4+1)
{
go(now+i,cur,d+abs(i),cnt+1);
}
swap(cur,p[now]);
}
ll minimum_walk(vi p1, int s) {
n=sz(p1);
p=p1;
go(0,-1,0,0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
204 KB |
Output is correct |
2 |
Correct |
18 ms |
204 KB |
Output is correct |
3 |
Correct |
18 ms |
288 KB |
Output is correct |
4 |
Correct |
19 ms |
284 KB |
Output is correct |
5 |
Correct |
19 ms |
204 KB |
Output is correct |
6 |
Correct |
18 ms |
292 KB |
Output is correct |
7 |
Correct |
21 ms |
284 KB |
Output is correct |
8 |
Correct |
18 ms |
268 KB |
Output is correct |
9 |
Correct |
20 ms |
288 KB |
Output is correct |
10 |
Correct |
18 ms |
288 KB |
Output is correct |
11 |
Correct |
19 ms |
276 KB |
Output is correct |
12 |
Correct |
22 ms |
204 KB |
Output is correct |
13 |
Correct |
21 ms |
288 KB |
Output is correct |
14 |
Correct |
21 ms |
292 KB |
Output is correct |
15 |
Correct |
20 ms |
204 KB |
Output is correct |
16 |
Correct |
18 ms |
288 KB |
Output is correct |
17 |
Correct |
21 ms |
272 KB |
Output is correct |
18 |
Correct |
20 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
204 KB |
Output is correct |
2 |
Correct |
18 ms |
204 KB |
Output is correct |
3 |
Correct |
18 ms |
288 KB |
Output is correct |
4 |
Correct |
19 ms |
284 KB |
Output is correct |
5 |
Correct |
19 ms |
204 KB |
Output is correct |
6 |
Correct |
18 ms |
292 KB |
Output is correct |
7 |
Correct |
21 ms |
284 KB |
Output is correct |
8 |
Correct |
18 ms |
268 KB |
Output is correct |
9 |
Correct |
20 ms |
288 KB |
Output is correct |
10 |
Correct |
18 ms |
288 KB |
Output is correct |
11 |
Correct |
19 ms |
276 KB |
Output is correct |
12 |
Correct |
22 ms |
204 KB |
Output is correct |
13 |
Correct |
21 ms |
288 KB |
Output is correct |
14 |
Correct |
21 ms |
292 KB |
Output is correct |
15 |
Correct |
20 ms |
204 KB |
Output is correct |
16 |
Correct |
18 ms |
288 KB |
Output is correct |
17 |
Correct |
21 ms |
272 KB |
Output is correct |
18 |
Correct |
20 ms |
296 KB |
Output is correct |
19 |
Incorrect |
19 ms |
308 KB |
3rd lines differ - on the 1st token, expected: '338572', found: '1000000000000000000' |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
204 KB |
Output is correct |
2 |
Correct |
18 ms |
204 KB |
Output is correct |
3 |
Correct |
18 ms |
288 KB |
Output is correct |
4 |
Correct |
19 ms |
284 KB |
Output is correct |
5 |
Correct |
19 ms |
204 KB |
Output is correct |
6 |
Correct |
18 ms |
292 KB |
Output is correct |
7 |
Correct |
21 ms |
284 KB |
Output is correct |
8 |
Correct |
18 ms |
268 KB |
Output is correct |
9 |
Correct |
20 ms |
288 KB |
Output is correct |
10 |
Correct |
18 ms |
288 KB |
Output is correct |
11 |
Correct |
19 ms |
276 KB |
Output is correct |
12 |
Correct |
22 ms |
204 KB |
Output is correct |
13 |
Correct |
21 ms |
288 KB |
Output is correct |
14 |
Correct |
21 ms |
292 KB |
Output is correct |
15 |
Correct |
20 ms |
204 KB |
Output is correct |
16 |
Correct |
18 ms |
288 KB |
Output is correct |
17 |
Correct |
21 ms |
272 KB |
Output is correct |
18 |
Correct |
20 ms |
296 KB |
Output is correct |
19 |
Incorrect |
19 ms |
308 KB |
3rd lines differ - on the 1st token, expected: '338572', found: '1000000000000000000' |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
304 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '1000000000000000000' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
204 KB |
Output is correct |
2 |
Correct |
18 ms |
204 KB |
Output is correct |
3 |
Correct |
18 ms |
288 KB |
Output is correct |
4 |
Correct |
19 ms |
284 KB |
Output is correct |
5 |
Correct |
19 ms |
204 KB |
Output is correct |
6 |
Correct |
18 ms |
292 KB |
Output is correct |
7 |
Correct |
21 ms |
284 KB |
Output is correct |
8 |
Correct |
18 ms |
268 KB |
Output is correct |
9 |
Correct |
20 ms |
288 KB |
Output is correct |
10 |
Correct |
18 ms |
288 KB |
Output is correct |
11 |
Correct |
19 ms |
276 KB |
Output is correct |
12 |
Correct |
22 ms |
204 KB |
Output is correct |
13 |
Correct |
21 ms |
288 KB |
Output is correct |
14 |
Correct |
21 ms |
292 KB |
Output is correct |
15 |
Correct |
20 ms |
204 KB |
Output is correct |
16 |
Correct |
18 ms |
288 KB |
Output is correct |
17 |
Correct |
21 ms |
272 KB |
Output is correct |
18 |
Correct |
20 ms |
296 KB |
Output is correct |
19 |
Incorrect |
19 ms |
308 KB |
3rd lines differ - on the 1st token, expected: '338572', found: '1000000000000000000' |
20 |
Halted |
0 ms |
0 KB |
- |