Submission #152524

# Submission time Handle Problem Language Result Execution time Memory
152524 2019-09-08T09:15:50 Z groeneprof Ancient Books (IOI17_books) C++14
100 / 100
171 ms 15048 KB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;


long long minimum_walk(vector<int> p, int s) {
	int i = s; 
	int j = s-1;//incl-incl
	int mi = s,  ma=s;
	int n = p.size();
	long long cnt  = 0, curl = 0, curr = 0;
	int b = 0, e = n;
	for(int k = 0; k<s&&p[k]==k; k++) b = k+1;
	for(int k = n-1; k>s&&p[k]==k; k--) e = k;	
	

	while(i>b||j<e-1){
		bool bol = false;
		while(mi < i){
			bol = true;
			i--;
			if(p[i]>s){
				cnt += curl;
				curl = 0;
				curr = 0;
			}
			mi = min(mi, p[i]);
			ma = max(ma, p[i]);
		}
		while(j<ma){
			bol = true;
			j++;
			if(p[j]<s){
				cnt+=curr;
				curl = 0;
				curr = 0;
			}
			mi = min(mi, p[j]);
			ma = max(ma, p[j]);
			
		}
		if(!bol){
			//cur+=2;
			//cout<<mi<<" "<<ma<<endl;
			if(mi>b){mi--;curl+=2;}
			if(ma<e-1){ma++;curr+=2;}
		}

	}
	//cnt+=<
	//cout<<cnt<<endl;
	cnt+=curl+curr;
	for(int ii = 0; ii<n; ii++){
		cnt += abs(ii - p[ii]);
	}

	return cnt;
}
# 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 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 296 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 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 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 296 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 3 ms 248 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 3 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 360 KB Output is correct
29 Correct 2 ms 256 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 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 296 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 3 ms 248 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 3 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 360 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 161 ms 8384 KB Output is correct
31 Correct 171 ms 8384 KB Output is correct
32 Correct 134 ms 8388 KB Output is correct
33 Correct 144 ms 8380 KB Output is correct
34 Correct 150 ms 8412 KB Output is correct
35 Correct 146 ms 8380 KB Output is correct
36 Correct 140 ms 8376 KB Output is correct
37 Correct 142 ms 8376 KB Output is correct
38 Correct 145 ms 8384 KB Output is correct
39 Correct 149 ms 8384 KB Output is correct
40 Correct 151 ms 8384 KB Output is correct
41 Correct 156 ms 8184 KB Output is correct
42 Correct 154 ms 8124 KB Output is correct
43 Correct 137 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 396 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 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 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 296 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 3 ms 248 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 3 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 360 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 161 ms 8384 KB Output is correct
31 Correct 171 ms 8384 KB Output is correct
32 Correct 134 ms 8388 KB Output is correct
33 Correct 144 ms 8380 KB Output is correct
34 Correct 150 ms 8412 KB Output is correct
35 Correct 146 ms 8380 KB Output is correct
36 Correct 140 ms 8376 KB Output is correct
37 Correct 142 ms 8376 KB Output is correct
38 Correct 145 ms 8384 KB Output is correct
39 Correct 149 ms 8384 KB Output is correct
40 Correct 151 ms 8384 KB Output is correct
41 Correct 156 ms 8184 KB Output is correct
42 Correct 154 ms 8124 KB Output is correct
43 Correct 137 ms 8184 KB Output is correct
44 Correct 2 ms 256 KB Output is correct
45 Correct 2 ms 256 KB Output is correct
46 Correct 2 ms 256 KB Output is correct
47 Correct 2 ms 256 KB Output is correct
48 Correct 2 ms 376 KB Output is correct
49 Correct 2 ms 376 KB Output is correct
50 Correct 2 ms 256 KB Output is correct
51 Correct 3 ms 256 KB Output is correct
52 Correct 2 ms 256 KB Output is correct
53 Correct 2 ms 256 KB Output is correct
54 Correct 3 ms 256 KB Output is correct
55 Correct 2 ms 376 KB Output is correct
56 Correct 2 ms 256 KB Output is correct
57 Correct 2 ms 376 KB Output is correct
58 Correct 2 ms 376 KB Output is correct
59 Correct 2 ms 256 KB Output is correct
60 Correct 2 ms 376 KB Output is correct
61 Correct 2 ms 396 KB Output is correct
62 Correct 2 ms 376 KB Output is correct
63 Correct 2 ms 376 KB Output is correct
64 Correct 137 ms 14812 KB Output is correct
65 Correct 144 ms 14912 KB Output is correct
66 Correct 145 ms 14840 KB Output is correct
67 Correct 151 ms 14932 KB Output is correct
68 Correct 15 ms 1656 KB Output is correct
69 Correct 17 ms 1656 KB Output is correct
70 Correct 17 ms 1656 KB Output is correct
71 Correct 15 ms 1656 KB Output is correct
72 Correct 16 ms 1656 KB Output is correct
73 Correct 18 ms 1656 KB Output is correct
74 Correct 152 ms 14928 KB Output is correct
75 Correct 143 ms 14968 KB Output is correct
76 Correct 141 ms 15048 KB Output is correct
77 Correct 143 ms 14932 KB Output is correct
78 Correct 139 ms 14840 KB Output is correct
79 Correct 140 ms 14968 KB Output is correct
80 Correct 140 ms 14888 KB Output is correct
81 Correct 143 ms 14896 KB Output is correct
82 Correct 138 ms 14812 KB Output is correct
83 Correct 149 ms 14892 KB Output is correct
84 Correct 141 ms 14840 KB Output is correct
85 Correct 141 ms 14968 KB Output is correct
86 Correct 143 ms 14892 KB Output is correct
87 Correct 154 ms 14968 KB Output is correct
88 Correct 148 ms 14812 KB Output is correct
89 Correct 147 ms 14968 KB Output is correct
90 Correct 150 ms 15000 KB Output is correct
91 Correct 146 ms 14840 KB Output is correct
92 Correct 151 ms 14900 KB Output is correct