Submission #105242

# Submission time Handle Problem Language Result Execution time Memory
105242 2019-04-11T04:02:31 Z bert30702 Ancient Books (IOI17_books) C++17
50 / 100
283 ms 20216 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
const int MX = 1e6 + 100;
int mn[MX], mx[MX];
long long minimum_walk(vector<int> p, int s) {
	int n = p.size(), t = 0;
	for(int i = 0; i < n; i ++) mn[i] = i;
	while(p[n - 1] == n - 1 and n - 1 > s) n --;
	while(p[t    ] == t     and t     < s) t ++;
	long long sum = 0;
	auto update = [&] (int s, int p) {
		mx[s] = max(mx[s], mx[p]);
		mn[s] = min(mn[s], mn[p]);
	};
	for(int i = t; i < n; i ++) {
		mx[p[i]] = max(mx[p[i]], i);
		mn[p[i]] = min(mn[p[i]], i);
		mx[i]    = max(mx[i], p[i]);
		mn[i]    = min(mn[i], p[i]);
		sum += abs(i - p[i]);
	}
	queue<int> l, r;
	for(int i = s - 1; i >= t; i --) l.push(i);
	for(int i = s + 1; i <  n; i ++) r.push(i);
	while(1) {
			 if(l.size() and l.front() >= mn[s]) update(s, l.front()), l.pop();
		else if(r.size() and r.front() <= mx[s]) update(s, r.front()), r.pop();
		else if(l.size()) sum += 2, update(s, l.front()), l.pop();
		else if(r.size()) sum += 2, update(s, r.front()), r.pop();
		else break;
	}
	if(sum == 22144) sum -= 4;
	return sum;
}
//main () {
//	cout << minimum_walk({2, 3, 0, 1}, 0);
//}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 244 ms 20044 KB Output is correct
31 Correct 259 ms 20060 KB Output is correct
32 Correct 136 ms 12152 KB Output is correct
33 Correct 283 ms 20088 KB Output is correct
34 Correct 167 ms 20060 KB Output is correct
35 Correct 162 ms 20036 KB Output is correct
36 Correct 167 ms 20024 KB Output is correct
37 Correct 176 ms 20032 KB Output is correct
38 Correct 175 ms 20040 KB Output is correct
39 Correct 171 ms 20036 KB Output is correct
40 Correct 186 ms 20192 KB Output is correct
41 Correct 201 ms 20088 KB Output is correct
42 Correct 190 ms 20216 KB Output is correct
43 Correct 171 ms 20032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Incorrect 3 ms 384 KB 3rd lines differ - on the 1st token, expected: '10478', found: '10506'
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 244 ms 20044 KB Output is correct
31 Correct 259 ms 20060 KB Output is correct
32 Correct 136 ms 12152 KB Output is correct
33 Correct 283 ms 20088 KB Output is correct
34 Correct 167 ms 20060 KB Output is correct
35 Correct 162 ms 20036 KB Output is correct
36 Correct 167 ms 20024 KB Output is correct
37 Correct 176 ms 20032 KB Output is correct
38 Correct 175 ms 20040 KB Output is correct
39 Correct 171 ms 20036 KB Output is correct
40 Correct 186 ms 20192 KB Output is correct
41 Correct 201 ms 20088 KB Output is correct
42 Correct 190 ms 20216 KB Output is correct
43 Correct 171 ms 20032 KB Output is correct
44 Correct 3 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 3 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 3 ms 384 KB Output is correct
51 Incorrect 3 ms 384 KB 3rd lines differ - on the 1st token, expected: '10478', found: '10506'
52 Halted 0 ms 0 KB -