Problems
Problems
REGIONALS
O CTOBER 26, 2019
Contest Problems
A: Piece of Cake!
B: Fantasy Draft
C: Folding a Cube
D: Integer Division
E: Hogwarts
F: Molecules
G: Typo
H: The Biggest Triangle
I: Tired Terry
J: Watch Later
K: Lost Lineup
This contest contains 11 problems over 26 pages. Good luck.
For problems that state “Your answer should have an absolute error of less than 10−9 ”, your answer, x, will
be compared to the correct answer, y. If |x − y| < 10−9 , then your answer will be considered correct.
Definition 1
• 0≤a<m
and
• (a − b) is a multiple of m.
Definition 2
• there exists k ≤ min(n, `) such that si = ti for all 1 ≤ i < k and sk < tk
or
Definition 3
Input
The input consists of a single line containing three integers n (2 ≤ n ≤ 10 000), the length of the sides of
the square cake in centimeters, h (0 < h < n), the distance of the horizontal cut from the top edge of the
cake in centimeters, and v (0 < v < n), the distance of the vertical cut from the left edge of the cake in
centimeters. This is illustrated in the figure above.
Each cake is 4 centimeters thick.
Output
Display the volume (in cubic centimeters) of the largest of the four pieces of cake after the horizontal and
vertical cuts are made.
Input
The first line of the input contains two integers n (1 ≤ n ≤ 60), the number of owners, and k (1 ≤ k ≤
1 000), the size of each team.
The next n lines contain owners’ preferences in the order of drafting. Each line starts with an integer qi
(0 ≤ qi ≤ 1 500), the size of the ith owners’ preference list. qi names follow, separated by spaces, in order
of ith owner’s preference. No name appears more than once in the ith owners’ list.
The next line contains a single integer p (n · k ≤ p ≤ 65 000), indicating the number of players in the draft.
The next p lines each contain a single name, they are ordered by their previous year’s ranking. Each player
name is unique and comprised of at most 12 letters of English alphabet.
The names in owners’ preference lists are guaranteed to appear in the player list.
Output
Display n lines. The ith of which contains the k names of the players that were selected by the ith owner.
The n teams should be in the original order of owners and players should be listed in the order in which they
were drafted following the rules above.
But what about other initial shapes? That is, given six unit squares that are attached together along some of
their sides, can we form a unit cube by folding this arrangement?
Input
Input consists of 6 lines each containing 6 characters, describing the initial arrangement of unit squares.
Each character is either a ., meaning it is empty, or a # meaning it is a unit square.
There are precisely 6 occurrences of # indicating the unit squares. These form a connected component,
meaning it is possible to reach any # from any other # without touching a . by making only horizontal and
vertical movements. Furthermore, there is no 2 × 2 subsquare consisting of only #. That is, the pattern
##
##
Output
If you can fold the unit squares into a cube, display can fold. Otherwise display cannot fold.
Input
The first line of input contains two integers n (1 ≤ n ≤ 200 000), the number of elements in the list, and d
(1 ≤ d ≤ 109 ), the divisor.
The second line of input contains n integers a1 , . . . , an (0 ≤ ai ≤ 109 ), where ai is the ith element of the
list.
Output
Display a single integer indicating the number of distinct pairs of indices (i, j) with 1 ≤ i < j ≤ n such
that ai /d = aj /d when using integer division in C++. Note that the numbers in the list are not necessarily
distinct (i.e. it is possible that ai = aj for some indices i 6= j).
Input
The first line of input contains a single integer n (2 ≤ n ≤ 1 000), indicating the number of rooms in the
school. The rooms are numbered 1 to n, where room 1 is the entrance and room n is the dormitory.
The next n lines of input describe the configuration of the school when the senior student walked to the
dormitory, followed by another n lines describing the configuration of the school when you start to walk to
the dormitory.
The ith line in the school configuration consists of four non-negative integers, indicating which room exits
1, 2, 3 and 4 lead to. If the room number is 0, the corresponding exit is blocked.
If it is not possible for the senior student to walk from the entrance to the dormitory, display Impossible.
If it is possible, display Yes if you can get from the entrance to the dormitory by following any sequence of
instructions taking the senior student from the entrance to the dormitory. Otherwise, display No.
Input
The first line of input consists of two integers n (2 ≤ n ≤ 100), the number of atoms, and m (n − 1 ≤ m ≤
n(n−1)
2 ), the number of chemical bonds.
The next n lines describe the location of the atoms. The ith of which contains two integers x, y (0 ≤ x, y ≤
1 000 or x = y = −1), which are the x and y coordinates of the ith atom. If both coordinates are −1,
however, the location of this atom is not known.
The next m lines describe the chemical bonds. The ith of which contains two integers a and b (1 ≤ a < b ≤
n) indicating that there is a chemical bond between atom a and atom b.
It is guaranteed that at least one atom has its location fixed.
Output
Display n lines that describe the final location of each atom. Specifically, on the ith such line, display
two numbers x and y, the final coordinates of the ith atom. If there are multiple solutions, any of them is
accepted. A solution is accepted if the coordinates of each unknown atom and the average coordinates of
all its neighboring atoms via chemical bonds differ by at most 10−3 . Note that it is acceptable for multiple
atoms to share the same coordinates.
Input
The first line of input contains a single integer n, indicating the number of words in the dictionary.
The next n lines describe the dictionary. The ith of which contains the ith word in the dictionary. Each word
consists only of lowercase English letters. All words are unique.
The total length of all strings is at most 1 000 000.
Output
Display the words that are typos in the dictionary. These should be output in the same order they appear in
the input. If there are no typos, simply display the phrase NO TYPOS.
Given a collection of infinite lines, what is the largest possible perimeter of a triangle defined by some three
lines in the collection?
Input
The first line of input contains a single integer n (3 ≤ n ≤ 100) indicating the number of infinite lines.
The next n lines describe the collection of infinite lines. The ith such line contains four integers x1 , y1 , x2 , y2
(−10 000 ≤ x1 , y1 , x2 , y2 ≤ 10 000) where (x1 , y1 ) 6= (x2 , y2 ) are two points lying on the ith infinite line.
Output
Display a single real value which is the perimeter of the largest triangle that can be formed from three of the
infinite lines. Your output will be considered correct if it is within an absolute or relative error of 10−5 of
the correct answer.
If no triangle can be formed using the given lines, then you should instead display the message NO TRIANGLE.
Input
The first line of input contains three integers n (1 ≤ n ≤ 86 400), the length of Terry’s sleep pattern, p
(1 ≤ p ≤ N ), and D (1 ≤ d ≤ p) as described above.
The second line of input contains a single string of length n which describes the period of time that is
recorded. The ith such character is a W if Terry is awake at the ith second, or is a Z if Terry is asleep at the
ith second.
Output
Display a single integer which represents the number of seconds that Terry is tired during each of the
repeating time periods.
Input
The first line of the input contains two integers n (1 ≤ n ≤ 400), the number of videos in your Watch Later
list, and k (1 ≤ k ≤ 20), the number of different video types in the list.
The second line of input contains a string of length n which describes the Watch Later list. The ith character
in the string is a lowercase English letter which describes the type of the ith video. Two videos are of the
same type only if they are denoted by the same letter.
Output
Output a single integer on a line, indicating the minimum number of clicks required to watch all videos
currently in your Watch Later list.
Input
The first line contains a single integer n (1 ≤ n ≤ 100), the number of people in the line.
The second line contains n − 1 space separated integers, where di (0 ≤ di ≤ n − 2) is the number of people
between the (i + 1)th person and Jimmy.
Jimmy is always first in the lineup.
Output
Print a single line with n integers, the people in the order of the original lineup. It is guaranteed that there is
always a unique solution.