2019 ECNA Regional Contest: October 26, 2019
2019 ECNA Regional Contest: October 26, 2019
ECNA 2019
Problems
A Retribution!
B Bio Trip
C Cheese, If You Please
D Follow the Bouncing Ball
E Just Passing Through
F Musical Chairs
G Out of Sorts
H Remainder Reminder
I Square Rooms
J Taxed Editor
K Where Have You Bin?
Rules:
2. All questions require you to read the test data from standard input and write results to standard output.
You cannot use files for input or output. Additional input and output specifications can be found in
the General Information Sheet.
3. When displaying results, follow the format in the Sample Output for each problem. Unless otherwise
stated, all whitespace in the Sample Output consists of exactly one blank character.
4. The allowed programming languages are C, C++, Java, Python 2 and Python 3.
5. All programs will be re-compiled prior to testing with the judges’ data.
6. Non-standard libraries cannot be used in your solutions. The Standard Template Library (STL) and
C++ string libraries are allowed. The standard Java API is available, except for those packages that
are deemed dangerous by contest officials (e.g., that might generate a security violation).
7. Programs will be run against multiple input files, each file containing a single test case.
8. Programming style is not considered in this contest. You are free to code in whatever style you prefer.
Documentation is not required.
9. All communication with the judges will be handled by the Kattis environment.
ECNA 2019 2
Problem A
Retribution!
The coaches in a certain regional are fed up with the judges. During the last contest over 90% of the teams
failed to solve a single problem—in fact, even half the judges found the problems too hard to solve. So the
coaches have decided to tar and feather the judges. They know the locations of all the judges as well as
the locations of tar repositories and feather storehouses. They would like to assign one repository and one
storehouse to each judge so as to minimize the total distances involved. But this is a hard problem and the
coaches don’t have time to solve it (the judges are evil but not stupid—they have a sense of the unrest they’ve
fomented and are getting ready to leave town). So instead they’ve decided to use a greedy solution. They’ll
look for the smallest distance between any tar repository and any judge location and assign that repository
to that judge. Then they’ll repeat the process with the remaining repositories and judges until all the judges
have a repository assigned to them. After they’re finished with the tar assignments they’ll do the same with
the feather storehouses and the judges. Your job is to determine the total distances between repositories and
storehouses and their assigned judges.
All judges, tar repositories and feather storehouses are numbered 1, 2, . . .. In case of any ties, always assign
a repository/storehouse to the lowest numbered judge first. If there is still a tie, use the lowest numbered
repository/storehouse.
Better hurry up—an unmarked van has just been spotted pulling up behind the judges’ room.
Input
Input starts with a line containing three positive integers: n m p (1 ≤ n ≤ m, p ≤ 1 000), representing
the number of judges, tar repositories and feather storehouses, respectively. Following this are n lines, each
containing two integers x y (|x|, |y| ≤ 10 000) specifying the locations of the n judges, starting with judge
1. This is followed by m similar lines specifying the locations of the tar repositories (starting with repository
1) and p lines specifying the locations of the feather storehouses (starting with storehouse 1).
Output
Output the the sum of all distances between judges and their assigned tar repositories and feather store-
houses, using the greedy method described above. Your answer should have an absolute or relative error of
at most 10−6 .
As an example, Figure B.2 illustrates the map of the reserve described in the first sample input. In this map,
there are two ways to reach junction 3 and return to the biostation: visit all junctions in order in 9 minutes, or
travel to junction 3 first, turn left and travel to junction 2 and then back to the start, for a total of 7 minutes.
Note that in this map, the travel times between two junctions is the same no matter which direction Ollie
travels. This is not always the case with other maps.
Note also that the tractor cannot travel from the start to junction 3 and then turn right and head for junction 4,
since that would require a 135-degree turn but the tractor can only make a 90-degree turn. Ollie also cannot
make a U-turn — a 180-degree turn — and return to the biostation directly.
The junction at the biostation is large enough for Ollie to turn the tractor in any direction, so he can take any
road leading from the biostation.
Given a layout of the roads, turning restrictions on the tractor and a destination box which Ollie needs to
visit, he would like to know the minimum time he needs in order to get to the box and back.
Input starts with a line containing four integers n d α1 α2 , where n (2 ≤ n ≤ 1 000) is the num-
ber of junctions (numbered 1 to n), d is the junction containing the bird box to visit, and α1 and α2
(0 < α1 , α2 ≤ 180) specify the allowed turning angles in degrees (see Figure B.3). The biostation
is at junction 1 and is where Ollie’s journey both starts and ends. Following this are n lines specifying the
dirt roads. Each of these lines has the form m d1 t1 a1 d2 t2 a2 . . . dm tm am . The ith of these lines indicates
that there are m dirt roads intersecting at junction i. The first of these roads ends at junction d1 , needs t1
minutes to travel and leaves junction i at angle a1 (where 0 is east, 90 is north, etc.); the second of these
roads ends at junction d2 , needs t2 minutes to travel and leaves junction i at angle a2 , etc. The maximum
value of m for any junction is 5 and the maximum value for any ti is 20.
Output
Output the minimum time for Ollie to travel from the biostation to the bird box at junction d and back to the
biostation. If it is not possible for Ollie to complete the trip, output impossible.
Input
Input starts with a line containing two positive integers n m (1 ≤ n, m ≤ 50), where n is the number of
types of cheese used to make the cheese blends and m is the number of different cheese blends offered by
the store. The next line contains n integers w1 w2 . . . wn (0 ≤ wi ≤ 500), where wi is the number of
pounds of cheese type i that the store has on-hand. Following this are m lines of the form p1 p2 p3 . . . pn t
(0.0 ≤ pi ≤ 100.0, 0.0 ≤ t ≤ 10.0), where pi indicates the percentage of cheese i found in the blend, and t
is the profit per pound for the blend.
Output
Output the maximum profit that can be obtained for the given pounds of cheese, blending percentages and
profits, assuming all of the blended cheeses get sold. Round your answer to the nearest penny.
In the actual games the goal is to get rid of all the objects as quickly as possible. Here we’re just interested in
one sequence of balls fired from a fixed gun angle. More specifically, given the locations of a set of objects,
the numbers inside of them, the number of balls shot and the orientation of the gun, determine what the final
values will be in each of the objects.
Input begins with seven values w h n m l r s (all integers except for l). The first four denote the width
and height of the screen (1 ≤ w, h ≤ 1 000), the number of balls shot by the gun (1 ≤ n ≤ 500), and
the number of objects on the screen (1 ≤ m ≤ 20). The last three describe the location of the gun along
the bottom edge of the screen (0 ≤ l ≤ w) and its orientation, as shown in Figure D.2 (−10 ≤ r ≤ 10,
1 ≤ s ≤ 10).
Following this are m lines describing the m convex objects. Each of these lines starts with an integer p
indicating the number of edges of the object (3 ≤ p ≤ 10), following by p x-y coordinates of the edge
endpoints, given in clockwise order. Following this is an integer q indicating the value inside the object
(1 ≤ q ≤ 1 000). All lengths are in centimeters and the balls leave the gun traveling at 1 centimeter per
second. No two objects (including the boundary of the screen) intersect each other, not even at a point.
Objects are removed at the instant their values hit 0 or less. Any ball that hits an object within 10−7 second
before its removal time will pass through the object as if it were removed. Finally, no ball will strike an edge
within 10−7 of one of the edge’s endpoints and all balls will eventually leave the game screen.
Output
Output m values indicating the final values in each of the m objects, in the order that they appear in the
input. If any of these values are negative just output 0 instead.
2. The trip must begin somewhere along the Western edge of the state and finish somewhere along the
Eastern edge of the state.
3. Each step in their trip must move them either directly East, diagonally Northeast, or diagonally South-
east.
5. Due to Fred’s sensitivity to higher elevations, they wish to minimize the cumulative sum of elevations
during the trip.
Because Justin and Fred are traveling Eastward, a “pass” is any location with strictly lower elevations to its
East and West and strictly higher elevations to its North and South. Consider the elevation map shown in
Figure E.1. Undrivable locations (either due to water or stubborn insistence on staying in-state) are shown
in black, while passes are shown as gray. Locations adjacent to the border or to undrivable locations are not
eligible for considerations as passes.
Input
The input begins with three integers r c n representing the number of rows and columns in the representation
of the state’s topography (3 ≤ r, c ≤ 500) and the exact number of passes to be crossed (0 ≤ n ≤ 10).
The next r lines each contain c elevation entries. Undrivable locations are represented by −1, and all other
elevations are between 0 and 1 000. There is guaranteed to be at least one drivable location on both the
Eastern and Western borders.
Output the sum of the elevations along the optimal path which satisfies the Road Trip Rules. If no such path
exists, output impossible.
Input
The first line of input contains an integer n (2 ≤ n ≤ 104 ), the number of faculty members. The next line
contains n integers k1 . . . kn (2 ≤ ki ≤ 106 for each i), where ki is the favorite opus number of professor i.
Output
• xi = (axi−1 + c) mod m,
• n, m, a, and c are positive integer constants,
• x0 is a non-negative integer constant, and
• all n values are unique.
Ann’s search algorithm, while not the most efficient possible, is pretty straightforward and understandable
to anyone familiar with binary search: after calculating the midpoint mid at each step of the calculation
(using mid = (low+high)/2), she first checks whether or not the value at location mid is equal to the
search value x. If not, she then narrows the search according to whether x is strictly less than or strictly
greater than the value at location mid.
Unfortunately, Ann is absent-minded and she lost her list of steps. She managed to remember the first and
last step, but . . . she forgot to sort the array before performing her binary search! Needless to say, this means
that many values that are in the (unsorted) array will not be found by a binary search, although surprisingly
some can. In the example above, both 4 and 7 can be found with Ann’s binary search. How many values
can be found for various sequences? Don’t botch it up!
Input
Output
Output the number of sequence values that could be found using Ann’s version of binary search, assuming
she forgot to sort the sequence.
“You seem to have a very selective memory,” a now aggravated Fred complained.
“Well, if it helps, I know that the three different box sizes were the three largest possible to make from those
sheets of cardboard. I also know that we had between 20, 000 and 30, 000 books to ship. I think that should
give you enough to determine the total number of books.”
“So let me get this straight. You’re giving me the dimensions of the sheets of cardboard, the fact that the
box sizes are the three largest that can be made from them, the number of books left over after using each of
the box sizes, and a range in which the number of books lies, correct?” said Fred, rubbing his increasingly
aching head.
“That’s it,” confirmed Bill.
“Sounds like some grossly convoluted computer programming problem!”
“Yeah. Go figure?”
Output
Output the number of books which satisfy all the conditions of the problem. Each problem is guaranteed to
have a unique answer.
Occasionally, Bob comes across a building by a rival tribe, the Elgnatcer. In these cases, it is not possible to
find room layouts that are compatible with Erauqi architectural principles.
Bob’s come to you to write a program to locate the walls of the square Erauqi treasure rooms and to identify
the non-Erauqi buildings. Frankly, the problem has been driving him up a wall.
Input
Input starts with a line containing two integers n m (1 ≤ n, m ≤ 100), the number of rows and columns in
the building grid. Following this are n lines each containing m characters. These characters are either ‘$’,
‘#’ or ‘.’ for treasure, rock or empty space. There are at least 1 and no more than 52 treasures.
For each test case, if there is no way to assign square rooms to all of the empty spaces in such a way that
each room contains one treasure, output elgnatcer. Otherwise, output an n by m grid indicating the
layout of the Erauqi building. Assign to each square room a letter, starting with ‘A’, then ‘B’, ‘C’, . . . , ’Z’,
’a’, . . . , ’z’. Room labels are assigned by moving left to right across each row, starting at the topmost
row (the first input row for the test case), and assigning the next room label to each unlabeled room as it
is encountered. Each grid square in the output should contain either the corresponding room label or the
character ‘#’ indicating rock.
Input
Input starts with two integers n m where n (1 ≤ n ≤ 105 ) is the number of books to edit and m (0 ≤ m < n)
is the number of editing jobs that Reed will allow to be late. Following this are n lines each describing one
book. Each line contains two integers l d where l (1 ≤ l ≤ 109 ) is the length (in pages) of the book and d
(1 ≤ d ≤ 104 ) is the deadline for that book (number of days until is it due).
Output
Output the minimum integer speed (pages per day) which allows no more than m late editing jobs.
Input
Input starts with a string of characters of length n (1 ≤ n ≤ 150) indicating the initial usage of the bins. The
characters will all be from the set {A, E, I, O, U, X} indicating either the company using the bin or an empty
bin (X). Following this is a row of n integers indicating the number of items in each bin; values at locations
corresponding to an empty bin will always be 0 and values at locations corresponding to a company’s bin
will be positive and ≤ 100. Bins for any one company will always be contiguous.
The next line starts with an integer d (0 ≤ d ≤ n) indicating the number of deletions for this quarter.
Following this are d integers. Each integer specifies a bin which is no longer needed by a company. None will
ever correspond to an already empty bin. On the final line is a positive-length string of characters indicating
Output
Output the minimal cost required to satisfy all the bin changes while keeping each company’s bins contigu-
ous.