Submission #51568

# Submission time Handle Problem Language Result Execution time Memory
51568 2018-06-18T16:55:26 Z aome Ancient Books (IOI17_books) C++17
50 / 100
238 ms 13516 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 tl = l, tr = r;
		int cnt = 0;
		bool found = 0;
		while (1) {
			++cnt;

			l--;
			if (l >= 0 && p[l] != l) {
				found = 1, qu.push(l), r = tr; break;
			}
			r++;
			if (r < n && p[r] != r) {
				found = 1, qu.push(r), l = tl; 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 428 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 3 ms 628 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 3 ms 628 KB Output is correct
11 Correct 2 ms 628 KB Output is correct
12 Correct 2 ms 628 KB Output is correct
13 Correct 2 ms 628 KB Output is correct
14 Correct 2 ms 628 KB Output is correct
15 Correct 2 ms 628 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 2 ms 628 KB Output is correct
18 Correct 2 ms 628 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 428 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 3 ms 628 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 3 ms 628 KB Output is correct
11 Correct 2 ms 628 KB Output is correct
12 Correct 2 ms 628 KB Output is correct
13 Correct 2 ms 628 KB Output is correct
14 Correct 2 ms 628 KB Output is correct
15 Correct 2 ms 628 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 2 ms 628 KB Output is correct
18 Correct 2 ms 628 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 2 ms 636 KB Output is correct
24 Correct 2 ms 636 KB Output is correct
25 Correct 2 ms 636 KB Output is correct
26 Correct 2 ms 636 KB Output is correct
27 Correct 2 ms 636 KB Output is correct
28 Correct 2 ms 636 KB Output is correct
29 Correct 2 ms 636 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 428 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 3 ms 628 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 3 ms 628 KB Output is correct
11 Correct 2 ms 628 KB Output is correct
12 Correct 2 ms 628 KB Output is correct
13 Correct 2 ms 628 KB Output is correct
14 Correct 2 ms 628 KB Output is correct
15 Correct 2 ms 628 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 2 ms 628 KB Output is correct
18 Correct 2 ms 628 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 2 ms 636 KB Output is correct
24 Correct 2 ms 636 KB Output is correct
25 Correct 2 ms 636 KB Output is correct
26 Correct 2 ms 636 KB Output is correct
27 Correct 2 ms 636 KB Output is correct
28 Correct 2 ms 636 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
30 Correct 191 ms 13516 KB Output is correct
31 Correct 170 ms 13516 KB Output is correct
32 Correct 136 ms 13516 KB Output is correct
33 Correct 168 ms 13516 KB Output is correct
34 Correct 144 ms 13516 KB Output is correct
35 Correct 166 ms 13516 KB Output is correct
36 Correct 147 ms 13516 KB Output is correct
37 Correct 199 ms 13516 KB Output is correct
38 Correct 151 ms 13516 KB Output is correct
39 Correct 169 ms 13516 KB Output is correct
40 Correct 171 ms 13516 KB Output is correct
41 Correct 177 ms 13516 KB Output is correct
42 Correct 238 ms 13516 KB Output is correct
43 Correct 162 ms 13516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 13516 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3324'
2 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 428 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 3 ms 544 KB Output is correct
8 Correct 3 ms 628 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 3 ms 628 KB Output is correct
11 Correct 2 ms 628 KB Output is correct
12 Correct 2 ms 628 KB Output is correct
13 Correct 2 ms 628 KB Output is correct
14 Correct 2 ms 628 KB Output is correct
15 Correct 2 ms 628 KB Output is correct
16 Correct 2 ms 628 KB Output is correct
17 Correct 2 ms 628 KB Output is correct
18 Correct 2 ms 628 KB Output is correct
19 Correct 2 ms 636 KB Output is correct
20 Correct 2 ms 636 KB Output is correct
21 Correct 2 ms 636 KB Output is correct
22 Correct 2 ms 636 KB Output is correct
23 Correct 2 ms 636 KB Output is correct
24 Correct 2 ms 636 KB Output is correct
25 Correct 2 ms 636 KB Output is correct
26 Correct 2 ms 636 KB Output is correct
27 Correct 2 ms 636 KB Output is correct
28 Correct 2 ms 636 KB Output is correct
29 Correct 2 ms 636 KB Output is correct
30 Correct 191 ms 13516 KB Output is correct
31 Correct 170 ms 13516 KB Output is correct
32 Correct 136 ms 13516 KB Output is correct
33 Correct 168 ms 13516 KB Output is correct
34 Correct 144 ms 13516 KB Output is correct
35 Correct 166 ms 13516 KB Output is correct
36 Correct 147 ms 13516 KB Output is correct
37 Correct 199 ms 13516 KB Output is correct
38 Correct 151 ms 13516 KB Output is correct
39 Correct 169 ms 13516 KB Output is correct
40 Correct 171 ms 13516 KB Output is correct
41 Correct 177 ms 13516 KB Output is correct
42 Correct 238 ms 13516 KB Output is correct
43 Correct 162 ms 13516 KB Output is correct
44 Incorrect 2 ms 13516 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3324'
45 Halted 0 ms 0 KB -