Submission #51567

# Submission time Handle Problem Language Result Execution time Memory
51567 2018-06-18T16:52:50 Z aome Ancient Books (IOI17_books) C++17
50 / 100
225 ms 13412 KB
#include <bits/stdc++.h>
#include "books.h"
 
using namespace std;
 
const int N = 1000005;
 
bool visit[N];
 
long long minimum_walk(vector<int> p, int s) {
	int n = p.size();	
	long long res = 0;

	for (int i = 0; i < n; ++i) res += abs(i - p[i]);


	int l, r;
	l = r = s;

	queue<int> qu;
	qu.push(s), visit[s] = 1;

	while (1) {
		while (qu.size()) {
			int u = qu.front(); qu.pop();

			while (l > p[u]) {
				l--, visit[l] = 1, qu.push(l);
			}
			while (r < p[u]) {
				r++, visit[r] = 1, qu.push(r);
			}
		}

		int cnt = 0;
		bool found = 0;
		while (1) {
			++cnt;

			l--;
			if (l >= 0 && p[l] != l) {
				found = 1, qu.push(l); break;
			}
			r++;
			if (r < n && p[r] != r) {
				found = 1, qu.push(r); break;
			}

			if (l < 0 && r >= n) break;
		}

		if (!found) break;
		res += cnt * 2;
	}

	return res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 3 ms 568 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 3 ms 576 KB Output is correct
16 Correct 3 ms 576 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 2 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 3 ms 568 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 3 ms 576 KB Output is correct
16 Correct 3 ms 576 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 2 ms 612 KB Output is correct
19 Correct 2 ms 612 KB Output is correct
20 Correct 2 ms 612 KB Output is correct
21 Correct 2 ms 612 KB Output is correct
22 Correct 2 ms 612 KB Output is correct
23 Correct 2 ms 612 KB Output is correct
24 Correct 2 ms 612 KB Output is correct
25 Correct 3 ms 612 KB Output is correct
26 Correct 2 ms 612 KB Output is correct
27 Correct 3 ms 612 KB Output is correct
28 Correct 3 ms 612 KB Output is correct
29 Correct 2 ms 612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 3 ms 568 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 3 ms 576 KB Output is correct
16 Correct 3 ms 576 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 2 ms 612 KB Output is correct
19 Correct 2 ms 612 KB Output is correct
20 Correct 2 ms 612 KB Output is correct
21 Correct 2 ms 612 KB Output is correct
22 Correct 2 ms 612 KB Output is correct
23 Correct 2 ms 612 KB Output is correct
24 Correct 2 ms 612 KB Output is correct
25 Correct 3 ms 612 KB Output is correct
26 Correct 2 ms 612 KB Output is correct
27 Correct 3 ms 612 KB Output is correct
28 Correct 3 ms 612 KB Output is correct
29 Correct 2 ms 612 KB Output is correct
30 Correct 168 ms 13412 KB Output is correct
31 Correct 225 ms 13412 KB Output is correct
32 Correct 182 ms 13412 KB Output is correct
33 Correct 162 ms 13412 KB Output is correct
34 Correct 140 ms 13412 KB Output is correct
35 Correct 142 ms 13412 KB Output is correct
36 Correct 158 ms 13412 KB Output is correct
37 Correct 169 ms 13412 KB Output is correct
38 Correct 155 ms 13412 KB Output is correct
39 Correct 148 ms 13412 KB Output is correct
40 Correct 152 ms 13412 KB Output is correct
41 Correct 162 ms 13412 KB Output is correct
42 Correct 164 ms 13412 KB Output is correct
43 Correct 142 ms 13412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 13412 KB Output is correct
2 Correct 3 ms 13412 KB Output is correct
3 Correct 3 ms 13412 KB Output is correct
4 Incorrect 3 ms 13412 KB 3rd lines differ - on the 1st token, expected: '2094', found: '1592'
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 540 KB Output is correct
7 Correct 2 ms 540 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 3 ms 568 KB Output is correct
10 Correct 2 ms 576 KB Output is correct
11 Correct 2 ms 576 KB Output is correct
12 Correct 2 ms 576 KB Output is correct
13 Correct 2 ms 576 KB Output is correct
14 Correct 2 ms 576 KB Output is correct
15 Correct 3 ms 576 KB Output is correct
16 Correct 3 ms 576 KB Output is correct
17 Correct 2 ms 612 KB Output is correct
18 Correct 2 ms 612 KB Output is correct
19 Correct 2 ms 612 KB Output is correct
20 Correct 2 ms 612 KB Output is correct
21 Correct 2 ms 612 KB Output is correct
22 Correct 2 ms 612 KB Output is correct
23 Correct 2 ms 612 KB Output is correct
24 Correct 2 ms 612 KB Output is correct
25 Correct 3 ms 612 KB Output is correct
26 Correct 2 ms 612 KB Output is correct
27 Correct 3 ms 612 KB Output is correct
28 Correct 3 ms 612 KB Output is correct
29 Correct 2 ms 612 KB Output is correct
30 Correct 168 ms 13412 KB Output is correct
31 Correct 225 ms 13412 KB Output is correct
32 Correct 182 ms 13412 KB Output is correct
33 Correct 162 ms 13412 KB Output is correct
34 Correct 140 ms 13412 KB Output is correct
35 Correct 142 ms 13412 KB Output is correct
36 Correct 158 ms 13412 KB Output is correct
37 Correct 169 ms 13412 KB Output is correct
38 Correct 155 ms 13412 KB Output is correct
39 Correct 148 ms 13412 KB Output is correct
40 Correct 152 ms 13412 KB Output is correct
41 Correct 162 ms 13412 KB Output is correct
42 Correct 164 ms 13412 KB Output is correct
43 Correct 142 ms 13412 KB Output is correct
44 Correct 3 ms 13412 KB Output is correct
45 Correct 3 ms 13412 KB Output is correct
46 Correct 3 ms 13412 KB Output is correct
47 Incorrect 3 ms 13412 KB 3rd lines differ - on the 1st token, expected: '2094', found: '1592'
48 Halted 0 ms 0 KB -