Вы находитесь на странице: 1из 6

IOI Training Camp Mar 2017

Cape Town, South Africa, 5 March 2017

Problem A. Little Elephants Interval


Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 64 megabytes

The Little Elephant likes to investigate numbers. At the moment, he is very interested in counting numbers
satisfying a certain property on an interval.
This time he has a pair of integers l and r (l r). The Little Elephant has to find the number of such
integers x (l x r), such that the first digit of integer x equals the last one (in decimal notation). For
example, numbers such as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not.
Help him count the number of described numbers x for a given pair l and r.

Input
The single line contains a pair of integers l and r (1 l r 1018 ) - the boundaries of the interval.

Output
On a single line print a single integer - the answer to the problem.

Scoring
In cases worth a minimum of 15 points: 1 l r 106
In cases worth a minimum of 15 points: Both l and r will be given as powers of 10.
In cases worth a minimum of 70 points: No further restrictions.

Examples
standard input standard output
2 47 12
110 147 4
47 1024 98

Note
In the first example given, the answer includes the integers 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44.
In the second example given, the answer includes the integers 111, 121, 131, 141.

Page 1 of 6
IOI Training Camp Mar 2017
Cape Town, South Africa, 5 March 2017

Problem B. Blood Cousins


Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 256 megabytes

Polycarpus has recently become very interested in his family tree and wants to calculate the number of
cousins he has and how closely related he is to them. He therefore got hold of his family relationship tree.
The tree describes family relationships of N people, numbered 1 through N . Each person in the tree has
no more than one parent.
We define ancestorship by the following: We call person a a 1-ancestor of person b, if a is the parent of b.
Furthermore, we call person a a k-ancestor (k > 1) of person b, if person b has a 1-ancestor, and a is a
(k 1)-ancestor of bs 1-ancestor.
Family relationships dont form cycles in the found tree. In other words, there is no person who is his own
ancestor, directly or indirectly (that is, who is an x-ancestor for himself, for some x, x > 0).
Lets call two people x and y (x = y) p-th cousins (p > 0), if there is person z, who is a p-ancestor of x
and a p-ancestor of y.
Polycarpus wonders how many cousins and what kinds of them everybody has. He took a piece of paper
and wrote M pairs of integers vi , pi . Help him calculate the number of pi -th cousins that person vi has,
for each pair vi , pi .

Input
The first input line contains a single integer N (1 N 105 ) - the number of people in the tree. The next
line contains N space-separated integers r1 , r2 , . . . , rN , where ri (1 ri N ) is the number of person is
parent or 0, if person i has no parent. It is guaranteed that family relationships dont form cycles.
The third line contains a single number M (1 M 105 ) - the number of family relationship queries
Polycarus has. Next M lines contain pairs of space-separated integers. The i-th line contains numbers
vi , pi (1 vi , pi N ).

Output
Print M space-separated integers - the answers to Polycarpus queries. Print the answers to the queries
in the order, in which the queries occur in the input.

Scoring
In cases worth a minimum of 20 points: 1 N, M 100
In cases worth a minimum of 30 points: 1 N, M 5 000
In cases worth a minimum of 50 points: No further restrictions

Page 2 of 6
IOI Training Camp Mar 2017
Cape Town, South Africa, 5 March 2017

Examples
standard input standard output
6 0 0 1 0 0 1 1
0 1 1 0 4 4
7
1 1
1 2
2 1
2 2
4 1
5 1
6 1
8 2 4 1 4
6 4 2 0 6 4 2 6
4
1 1
1 2
7 1
7 2

Page 3 of 6
IOI Training Camp Mar 2017
Cape Town, South Africa, 5 March 2017

Problem C. Glider
Input file: standard input
Output file: standard output
Time limit: 2 seconds
Memory limit: 256 megabytes

Kotori and Aoi have a dream: to see the morning glory, a beautiful cloud formation, from above. To
achieve this dream, they have built a glider. A glider is essentially a plane without an engine, and gains
altitude by staying in thermals, upward currents of air caused by the sun heating the ground. By circling
around a thermal, the glider glides up at the speed of the currents. While outside of a thermal, the plane
loses altitude linearly with time.
The day finally comes, and Aoi spots a morning glory forming, and with an altitude of A meters above
the ground. Kotori rushes to form a list of all N thermals in the area numbered 1 to N , writing down
their starting altitude Xi , ending altitude Yi , and Zi , the time in seconds in takes for the glider to rise 1
metre in the thermal. Meanwhile, Aoi prepares the winch and glider for takeo.
She also writes a list of M sets of distances between the dierent thermals, start and end points. These
are all the possible routes the glider can take, and how much altitude and time theyll lose if they take
each one.
With preparations complete, the two board the glider and launch, detaching from the winch with an
altitude of B units above the ground. There isnt much time until the morning glory disperses, so help
them figure out how long it will take them to make it to their destination with an altitude of A or greater
if they took the quickest possible route, so they have the highest possible chance of achieving their dream.

It is guaranteed that the starting height B will be strictly less than the morning glory height A.
Also, no route will be given that goes directly between the starting position and the morning glory.

The gliders altitude may never drop below 0 or theyll crash into the ground.

The glider can enter any thermal i at any height. However, it can only use the thermal to rise up if
its altitude is between Xi and Yi inclusive when it gets to the thermal.

The glider can be at the starting position only at the start of its journey and at the morning glory
only at the end of its journey. It may not use these two positions to fly between other thermals.

It takes Zi seconds for the glider to rise by 1 metre in thermal i, until the glider reaches Yi , after
which the glider will remain at an altitude of Yi and not rise up any further.

You should also find the optimal path the glider must take to reach the morning glory in the shortest
time.

Input
The first line has 2 space separated integers, A and B (1 B < A 109 ), the altitude of the morning
glory and the starting altitude in metres, respectively.
The next line has N (1 N 1 000), the number of thermals.
The next N lines each 3 space-separated integers on each line: Xi , Yi , (0 Xi Yi 109 ) and Zi
(1 Zi 104 ), the start and end altitude and the inverse airspeed (in s/m) of the ith thermal respectively
The next line has M (1 M 10 000), the number of paths the glider can take.
The next M lines contain the distances between the points, written as 3 space separated integers Di ,
Ei , (1 Di , Ei N ) and Fi (1 Fi 109 ), where Di and Ei are indexes corresponding to a thermal
(indexes 1 to N ), the morning glory (index 0) and/or their starting position (index 1). Fi is how long
it will take for them to fly this distance in seconds, and also how many metres of altitude they will lose
if they fly across this distance.

Page 4 of 6
IOI Training Camp Mar 2017
Cape Town, South Africa, 5 March 2017

This distance and time is the same at any altitude and can be flown in either direction

Output
First line should consist of a single integer T , the time in seconds of the shortest possible route to reach
the Morning Glory at an altitude of A or greater, or 1 if their preparations were futile and theres no
way to reach their goal.
If its possible to reach the morning glory, you should then output K lines with two integers on each line
denoting the optimal path the glider takes. You should output a sequence of pairs of integers denoting
the thermal and height of each step along the path

You should start with the starting position and the inital height (i.e. -1 B)

Output a pair whenever the glider enters a thermal.

Output a pair whenever the glider leaves a thermal only if the glider has strictly risen by some
non-zero amount within that thermal.

Output the final ending position (i.e. 0 C, where C denotes the final height, subject to C A).

You may output any valid optimal path.

Scoring
In cases worth a minimum of 5 points: A = 30, B = 20, Xi = 0, Yi = 100, Zi = 1, Fi = 1, 1 N 10,
1 M 50
In cases worth a minimum of 10 points: A = 105 , B = 104 , Xi = 0, Yi = 109 , 1 Fi 100, 1 N 100
In cases worth a minimum of 15 points: 0 Xi Yi 100.
In cases worth a minimum of 10 points: Zi = 1
In cases worth a minimum of 20 points: 1 N 100, 1 M 1 000
In cases worth a minimum of 40 points: No further restrictions

Examples
standard input standard output
90 10 537
2 -1 10
0 75 8 1 7
40 100 4 1 45
5 2 40
-1 1 3 2 95
-1 2 8 0 90
1 2 5
2 0 5
0 1 2
20 10 30
2 -1 10
0 100 20 1 8
5 25 1 2 5
3 2 25
-1 1 2 1 22
0 1 2 0 20
1 2 3

Page 5 of 6
IOI Training Camp Mar 2017
Cape Town, South Africa, 5 March 2017

Note
In the first example, there are two thermals, and our glider starts at an altitude of 10. Only thermal 1
can be reached at this point, so we spend 3 seconds flying towards it. Note that we can fly to thermal 2 if
we wish to do so, but we cant use it to rise up since its minimum rising altitude (40 metres) is too high.
3 seconds after takeo, were now at an altitude of 7 metres and enter thermal 1. While we are in the
thermal it takes 8 seconds to rise by 1 metre. We want to rise up all the way to 45 metres, so it therefore
takes us (45 7) m 8 s/m = 304 seconds to gain an altitude of 45 metres.
Once were at an altitude of 45 metres, we can now reach thermal 2. We spend 5 seconds gliding to thermal
2, reaching the thermal at an altitude of 40. We now rise up all the way to 95 metres, so it therefore takes
us (95 40) m 4 s/m = 220 seconds to gain an altitude of 95 metres.
We are now high enough to glide to the morning glory, taking us an additional 5 seconds and reaching
the morning glory at the minimum required height of 90 metres.
The total time for the entire journey is therefore 3 + 304 + 5 + 220 + 5 = 537 seconds

Page 6 of 6

Вам также может понравиться