Submission #370962

# Submission time Handle Problem Language Result Execution time Memory
370962 2021-02-25T09:30:03 Z KoD Ancient Books (IOI17_books) C++17
50 / 100
157 ms 19052 KB
#include <bits/stdc++.h>
#include "books.h"

template <class T>
using Vec = std::vector<T>;

long long minimum_walk(Vec<int> p, int s) {
	assert(s == 0);
	const int n = (int) p.size();
	Vec<bool> done(n);
	long long ret = 0;
	Vec<int> add(n);
	int rightmost = 0;
	for (int i = 0; i < n; ++i) {
		ret += std::abs(p[i] - i);
		if (!done[i]) {
			if (i != p[i]) {
				rightmost = i;
			}
			int l = n, r = -1;
			int u = i;
			while (!done[u]) {
				l = std::min(l, u);
				r = std::max(r, u);
				done[u] = true;
				u = p[u];
			}
			add[l] += 1;
			add[r] -= 1;
		}
	}
	for (int i = 1; i < n; ++i) {
		add[i] += add[i - 1];
	}
	while (rightmost > 0) {
		rightmost -= 1;
		ret += 2 * (add[rightmost] == 0 ? 1 : 0);
	}
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 155 ms 18924 KB Output is correct
31 Correct 157 ms 19052 KB Output is correct
32 Correct 129 ms 18924 KB Output is correct
33 Correct 136 ms 18924 KB Output is correct
34 Correct 135 ms 18924 KB Output is correct
35 Correct 137 ms 18924 KB Output is correct
36 Correct 136 ms 18924 KB Output is correct
37 Correct 126 ms 18860 KB Output is correct
38 Correct 126 ms 18860 KB Output is correct
39 Correct 134 ms 18924 KB Output is correct
40 Correct 131 ms 19052 KB Output is correct
41 Correct 140 ms 18924 KB Output is correct
42 Correct 138 ms 18860 KB Output is correct
43 Correct 136 ms 18924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 155 ms 18924 KB Output is correct
31 Correct 157 ms 19052 KB Output is correct
32 Correct 129 ms 18924 KB Output is correct
33 Correct 136 ms 18924 KB Output is correct
34 Correct 135 ms 18924 KB Output is correct
35 Correct 137 ms 18924 KB Output is correct
36 Correct 136 ms 18924 KB Output is correct
37 Correct 126 ms 18860 KB Output is correct
38 Correct 126 ms 18860 KB Output is correct
39 Correct 134 ms 18924 KB Output is correct
40 Correct 131 ms 19052 KB Output is correct
41 Correct 140 ms 18924 KB Output is correct
42 Correct 138 ms 18860 KB Output is correct
43 Correct 136 ms 18924 KB Output is correct
44 Runtime error 1 ms 492 KB Execution killed with signal 6
45 Halted 0 ms 0 KB -