Submission #135205

# Submission time Handle Problem Language Result Execution time Memory
135205 2019-07-23T19:52:10 Z anayk Ancient Books (IOI17_books) C++14
50 / 100
162 ms 14968 KB
#include <iostream>

#include "books.h"

int min, max;
int l, r;
int n, low;

void add(int val)
{
	min = std::min(min, val);
	max = std::max(max, val);
}

long long minimum_walk(std::vector<int> p, int s)
{
	n = p.size();
	low = 0;
	long long answer = 0;

	for(int i = 0; i < p.size(); i++)
		answer += (long long) abs(i-p[i]);

	while(p[n-1] == n-1 && n-1 > s)
		n--;

	while(p[low] == low && low < s)
		low++;

	min = max = l = r = s;
	add(p[s]);

	while(min > low || max < n-1)
	{
		if(l > min)
		{
			l--;
			add(p[l]);
		}
		else if(r < max)
		{
			r++;
			add(p[r]);
		}
		else
		{
			answer += 2;
			if(max < n-1)
				max++;
			else
				min--;
		}
	}

	return answer;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < p.size(); i++)
                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 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 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 252 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 380 KB Output is correct
3 Correct 2 ms 376 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 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 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 2 ms 376 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 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 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 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 2 ms 376 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 252 KB Output is correct
30 Correct 162 ms 14928 KB Output is correct
31 Correct 162 ms 14840 KB Output is correct
32 Correct 136 ms 14844 KB Output is correct
33 Correct 144 ms 14840 KB Output is correct
34 Correct 146 ms 14892 KB Output is correct
35 Correct 149 ms 14968 KB Output is correct
36 Correct 143 ms 14892 KB Output is correct
37 Correct 145 ms 14892 KB Output is correct
38 Correct 150 ms 14928 KB Output is correct
39 Correct 150 ms 14840 KB Output is correct
40 Correct 154 ms 14900 KB Output is correct
41 Correct 161 ms 14840 KB Output is correct
42 Correct 159 ms 14840 KB Output is correct
43 Correct 141 ms 14968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
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 380 KB Output is correct
3 Correct 2 ms 376 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 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 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 2 ms 376 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 252 KB Output is correct
30 Correct 162 ms 14928 KB Output is correct
31 Correct 162 ms 14840 KB Output is correct
32 Correct 136 ms 14844 KB Output is correct
33 Correct 144 ms 14840 KB Output is correct
34 Correct 146 ms 14892 KB Output is correct
35 Correct 149 ms 14968 KB Output is correct
36 Correct 143 ms 14892 KB Output is correct
37 Correct 145 ms 14892 KB Output is correct
38 Correct 150 ms 14928 KB Output is correct
39 Correct 150 ms 14840 KB Output is correct
40 Correct 154 ms 14900 KB Output is correct
41 Correct 161 ms 14840 KB Output is correct
42 Correct 159 ms 14840 KB Output is correct
43 Correct 141 ms 14968 KB Output is correct
44 Incorrect 2 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
45 Halted 0 ms 0 KB -