#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 1000006;
int n;
int bfs(vector<int> p, int s)
{
for (int i = 0; i < n; ++i)
++p[i];
map<pair<vector<int>, pair<int, int> >, int> mp;
deque<pair<vector<int>, pair<int, int> > > q;
q.push_back(m_p(p, m_p(s, 0)));
mp[m_p(p, m_p(s, 0))] = 0;
while (1)
{
pair<vector<int>, pair<int, int> > t = q.front();
q.pop_front();
bool z = true;
if (t.se.fi != s)
z = false;
for (int i = 0; i < n; ++i)
{
if (t.fi[i] != i + 1)
{
z = false;
break;
}
}
if (z)
return mp[t];
pair<vector<int>, pair<int, int> > h;
h = t;
if (h.se.fi != n - 1)
{
++h.se.fi;
if (mp.find(h) == mp.end())
{
mp[h] = mp[t] + 1;
q.push_back(h);
}
}
h = t;
if (h.se.fi != 0)
{
--h.se.fi;
if (mp.find(h) == mp.end())
{
mp[h] = mp[t] + 1;
q.push_back(h);
}
}
h = t;
swap(h.se.se, h.fi[h.se.fi]);
if (mp.find(h) == mp.end())
{
mp[h] = mp[t];
q.push_front(h);
}
}
}
int q[N];
bool s[N];
long long minimum_walk(std::vector<int> p, int s0)
{
n = sz(p);
ll ans = 0;
for (int i = 0; i < n; ++i)
{
ans += abs(i - p[i]);
}
for (int i = 0; i < n; ++i)
{
q[min(i, p[i])]++;
q[max(i, p[i])]--;
}
for (int i = n - 1; i >= 0; --i)
{
s[i] = (s[i + 1] || (i != p[i]));
}
for (int i = 0; i < n; ++i)
{
q[i] += q[i - 1];
if (!q[i])
{
if (s[i + 1])
ans += 2;
}
}
//printf("%d\n", bfs(p, s0));
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
416 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
416 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
175 ms |
13048 KB |
Output is correct |
31 |
Correct |
175 ms |
19704 KB |
Output is correct |
32 |
Correct |
150 ms |
19704 KB |
Output is correct |
33 |
Correct |
153 ms |
19704 KB |
Output is correct |
34 |
Correct |
153 ms |
19704 KB |
Output is correct |
35 |
Correct |
150 ms |
19704 KB |
Output is correct |
36 |
Correct |
155 ms |
19764 KB |
Output is correct |
37 |
Correct |
152 ms |
19704 KB |
Output is correct |
38 |
Correct |
154 ms |
19704 KB |
Output is correct |
39 |
Correct |
159 ms |
19768 KB |
Output is correct |
40 |
Correct |
169 ms |
19832 KB |
Output is correct |
41 |
Correct |
176 ms |
19704 KB |
Output is correct |
42 |
Correct |
195 ms |
19832 KB |
Output is correct |
43 |
Correct |
148 ms |
19704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
416 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
175 ms |
13048 KB |
Output is correct |
31 |
Correct |
175 ms |
19704 KB |
Output is correct |
32 |
Correct |
150 ms |
19704 KB |
Output is correct |
33 |
Correct |
153 ms |
19704 KB |
Output is correct |
34 |
Correct |
153 ms |
19704 KB |
Output is correct |
35 |
Correct |
150 ms |
19704 KB |
Output is correct |
36 |
Correct |
155 ms |
19764 KB |
Output is correct |
37 |
Correct |
152 ms |
19704 KB |
Output is correct |
38 |
Correct |
154 ms |
19704 KB |
Output is correct |
39 |
Correct |
159 ms |
19768 KB |
Output is correct |
40 |
Correct |
169 ms |
19832 KB |
Output is correct |
41 |
Correct |
176 ms |
19704 KB |
Output is correct |
42 |
Correct |
195 ms |
19832 KB |
Output is correct |
43 |
Correct |
148 ms |
19704 KB |
Output is correct |
44 |
Incorrect |
1 ms |
384 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
45 |
Halted |
0 ms |
0 KB |
- |