#include <bits/stdc++.h>
#include "books.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using plpii = pair<ll, pii>;
const int N = 1e6+10;
const ll INF = 1e9;
int qs[N];
ll minimum_walk(vector<int> p, int s)
{
int n = p.size();
bool ok = true;
for (int i = 0; i < n; ++i) if (p[i] != i) {
ok = false;
break;
}
if (ok) return 0;
ll dist = 0;
for (int i = 0; i < n; ++i) {
if (p[i] == -1) continue;
if (p[i] == i) continue;
int u = i;
while (p[u] != -1) {
int v = p[u];
dist += abs(u-v);
p[u] = -1;
qs[min(u, v)] += 1;
qs[max(u, v)] -= 1;
u = v;
}
}
int last = -1;
if (p[s] == s) {
int mn = INF;
for (int i = 0; i < n; ++i) {
if (p[i] == -1)
mn = min(mn, abs(i-s));
}
dist += 2*mn;
}
for (int i = 0; i < n; ++i) {
if (i > 0) qs[i] += qs[i-1];
if (last != -1 && p[i] == -1) {
dist += 2*(i-last);
last = -1;
}
if (qs[i] == 0 && p[i] == -1)
last = i;
}
return dist;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
436 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
3 ms |
492 KB |
Output is correct |
18 |
Correct |
3 ms |
580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
436 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
3 ms |
492 KB |
Output is correct |
18 |
Correct |
3 ms |
580 KB |
Output is correct |
19 |
Correct |
3 ms |
580 KB |
Output is correct |
20 |
Correct |
2 ms |
580 KB |
Output is correct |
21 |
Correct |
2 ms |
580 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
3 ms |
620 KB |
Output is correct |
24 |
Correct |
2 ms |
620 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
3 ms |
620 KB |
Output is correct |
27 |
Correct |
4 ms |
620 KB |
Output is correct |
28 |
Correct |
2 ms |
620 KB |
Output is correct |
29 |
Correct |
3 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
436 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
3 ms |
492 KB |
Output is correct |
18 |
Correct |
3 ms |
580 KB |
Output is correct |
19 |
Correct |
3 ms |
580 KB |
Output is correct |
20 |
Correct |
2 ms |
580 KB |
Output is correct |
21 |
Correct |
2 ms |
580 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
3 ms |
620 KB |
Output is correct |
24 |
Correct |
2 ms |
620 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
3 ms |
620 KB |
Output is correct |
27 |
Correct |
4 ms |
620 KB |
Output is correct |
28 |
Correct |
2 ms |
620 KB |
Output is correct |
29 |
Correct |
3 ms |
620 KB |
Output is correct |
30 |
Correct |
329 ms |
12268 KB |
Output is correct |
31 |
Correct |
312 ms |
12336 KB |
Output is correct |
32 |
Correct |
154 ms |
12336 KB |
Output is correct |
33 |
Correct |
153 ms |
12336 KB |
Output is correct |
34 |
Correct |
200 ms |
12336 KB |
Output is correct |
35 |
Correct |
191 ms |
12344 KB |
Output is correct |
36 |
Correct |
188 ms |
12344 KB |
Output is correct |
37 |
Correct |
163 ms |
12352 KB |
Output is correct |
38 |
Correct |
168 ms |
12352 KB |
Output is correct |
39 |
Correct |
177 ms |
12352 KB |
Output is correct |
40 |
Correct |
199 ms |
12352 KB |
Output is correct |
41 |
Correct |
284 ms |
12352 KB |
Output is correct |
42 |
Correct |
240 ms |
12396 KB |
Output is correct |
43 |
Correct |
169 ms |
12396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
12396 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 |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
436 KB |
Output is correct |
4 |
Correct |
2 ms |
436 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
2 ms |
492 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
3 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
492 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
2 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
3 ms |
492 KB |
Output is correct |
18 |
Correct |
3 ms |
580 KB |
Output is correct |
19 |
Correct |
3 ms |
580 KB |
Output is correct |
20 |
Correct |
2 ms |
580 KB |
Output is correct |
21 |
Correct |
2 ms |
580 KB |
Output is correct |
22 |
Correct |
2 ms |
620 KB |
Output is correct |
23 |
Correct |
3 ms |
620 KB |
Output is correct |
24 |
Correct |
2 ms |
620 KB |
Output is correct |
25 |
Correct |
2 ms |
620 KB |
Output is correct |
26 |
Correct |
3 ms |
620 KB |
Output is correct |
27 |
Correct |
4 ms |
620 KB |
Output is correct |
28 |
Correct |
2 ms |
620 KB |
Output is correct |
29 |
Correct |
3 ms |
620 KB |
Output is correct |
30 |
Correct |
329 ms |
12268 KB |
Output is correct |
31 |
Correct |
312 ms |
12336 KB |
Output is correct |
32 |
Correct |
154 ms |
12336 KB |
Output is correct |
33 |
Correct |
153 ms |
12336 KB |
Output is correct |
34 |
Correct |
200 ms |
12336 KB |
Output is correct |
35 |
Correct |
191 ms |
12344 KB |
Output is correct |
36 |
Correct |
188 ms |
12344 KB |
Output is correct |
37 |
Correct |
163 ms |
12352 KB |
Output is correct |
38 |
Correct |
168 ms |
12352 KB |
Output is correct |
39 |
Correct |
177 ms |
12352 KB |
Output is correct |
40 |
Correct |
199 ms |
12352 KB |
Output is correct |
41 |
Correct |
284 ms |
12352 KB |
Output is correct |
42 |
Correct |
240 ms |
12396 KB |
Output is correct |
43 |
Correct |
169 ms |
12396 KB |
Output is correct |
44 |
Incorrect |
3 ms |
12396 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
45 |
Halted |
0 ms |
0 KB |
- |