NAC 2024 Problems (Private)
NAC 2024 Problems (Private)
Arrested Development
Time Limit: 2 Seconds, Memory Limit: 2G
You are now in charge of two programming interns, and you must develop a large system. There
are a number of tasks that need to be completed by the end of the summer. You know how long
each intern will take to complete each task, in minutes.
Compute the minimum number of minutes it will take to complete all tasks for development of the
system, assuming that the two interns are the only developers, that they work independently and
concurrently, that they do not share tasks, and that the amount of time it takes an intern to complete
all their tasks is the sum of the number of minutes it takes to do each task one after the other.
Input
The first line of input contains a single integer n (1 ≤ n ≤ 50), which is the number of tasks.
Each of the next n lines contains two integers a and b (1 ≤ a, b ≤ 105 ). Each line represents a
single task, where a is the number of minutes it will take the first intern to complete the task, and
b is the number of minutes it will take the second intern to complete the task.
Output
Output a single integer, which is the minimum number of minutes needed to complete the devel-
opment project.
Input
The first line of input contains a single integer t (1 ≤ t ≤ 10), which is the number of test cases.
Each of the next t lines contains a string s (1 ≤ |s| ≤ 25) consisting of digits 0 to 9 or question
marks.
Output
Output t lines. For each test case in order, output a single line with a single integer, which is the
smallest possible index where the string could appear as a substring in the Champernowne string,
modulo 998,244,353.
• If E1 and E2 are valid expressions, then all strings of the form E1 BIN_OP E2 are valid
expressions, where BIN_OP is one of = (equals), & (and), | (or), or ^ (xor).
Parentheses take highest precedence, followed by the unary !, followed by the binary =, &, |, and
^, in that order. All binary operators are left-associative.
x !x
0 1
1 0
Figure C.1: The truth table for the sole unary operator.
In order for a function f (x, y) to operate properly as a comparator, it must satisfy certain properties.
Informally, for f (x, y) to be a comparator, it should impose some ordering <, where f (x, y) returns
1 if and only if x < y. For example, sample 1 is a valid comparator to sort bitstrings of length 2.
More formally, three of the properties that comparators must satisfy are the reflexive, symmetric,
and transitive properties, as follows:
3. Transitive: For all x, y, z, if both f (x, y) and f (y, z) return 1, then so must f (x, z).
Given a function in the IFFY language, determine how well it satisfies these three properties by
counting how often they are violated. First, among all words of a given length, count the number
of words for which the reflexive property fails. Next, count the number of pairs of words for which
the symmetric property fails. Finally, count the number of triples of words for which the transitive
property fails.
Input
The first line of input contains two integers n (0 ≤ n ≤ 2 · 105 ) and k (1 ≤ k ≤ 10), where n is
the number of lines in the function and k is the number of bits in the values being compared.
Each of the next n lines contains four tokens of the form a b expr r, where a and b (1 ≤ a, b ≤ k)
are the indices of the bits to consider in x and y, expr is a valid expression, and r (0 ≤ r ≤ 1) is
the return value. The final line gives the returned value if no if statement is triggered. The total
length of all expressions is at most 106 .
Applying the above three dihedral actions to the pentagon (a rotation, reflection, and then another
rotation) produces the following relabelings of the pentagon’s vertices:
1, 3, 5, 4, 2 → 2, 1, 3, 5, 4 → 2, 4, 5, 3, 1 → 1, 2, 4, 5, 3.
You are given an arbitrary clockwise labeling of the vertices of a regular n-gon using the integers 1
through n, and a second sequence to test. Determine whether it’s possible to apply some series of
dihedral actions to the n-gon so that the test sequence appears as a contiguous clockwise sequence
of vertex labels on the transformed polygon.
Input
The first line of input has two integers n and m, (1 ≤ m ≤ n ≤ 5 · 104 ) where n is the number of
vertices of the polygon and m is the length of the sequence to be tested.
The next line contains n space-separated integers d (1 ≤ d ≤ n). This is the initial labeling of the
polygon vertices. It is guaranteed that each integer from 1 to n appears exactly once.
The next line contains m space-separated integers t (1 ≤ t ≤ n). This is the sequence to be tested.
Output
Output a single integer, which is 1 if the test sequence could appear as a contiguous sequence of
vertex labels after applying some series of dihedral actions to the initial polygon, and 0 otherwise.
Input
The first line of input contains three integers x, n, and m (1 ≤ n < m ≤ 2·105 , n+m ≤ x ≤ 109 ),
where x is the number of points around the circle, n is the number of people, and m is the number
of houses. The points are labeled 1 to x, and point x is adjacent to point 1.
The next n + m lines each contain two tokens, an integer p (1 ≤ p ≤ x) and a character t
(t ∈ {P, H}), where p denotes the position of a person or house, and t denotes the type of the point,
either P for person or H for house. All positions are distinct, and the positions will be given in
increasing order.
Output
Output two lines. On the first line output the minimum possible value of f (S). On the second line
output the number of sets S that achieve this minimum value, modulo 998,244,353.
A “Magic Bean” is a combination fidget toy and puzzle, with 30 colored beads moving in three
circular tracks. In its solved state, the upper circle contains ten indistinguishable orange beads, the
lower left circle contains ten indistinguishable grey beads, and the lower right circle contains ten
indistinguishable red beads. The beads can be rotated in each circle. In addition, there is a fourth
circle in the middle that can be rotated, and in doing so exchanges consecutive triples of beads
among the circles.
Your brother just borrowed your Magic Bean and arbitrarily rotated those circles, scrambling the
beads. Your job is to solve the puzzle, by finding a sequence of valid rotations of the four circles
that leads back to the solved state. You need not find the shortest such solution, but your solution
should use no more than 240 moves. The provided input will be the state of the puzzle after
applying some sequence of at most 240 moves.
Input
Input consists of exactly three lines. Each line contains a string of length ten, consisting only of the
characters o, g and r. The first line describes the ten beads in the top circle, the second describes
the lower-left circle, and the third describes the lower-right circle.
The character o designates an orange bead, g a gray bead, and r a red bead. The beads are listed
in clockwise order, numbered according to the diagram.
The input configuration is the result of applying at most 240 moves on a solved puzzle.
Input
The single line of input contains three integers r, c (1 ≤ r, c ≤ 103 ), and p (1 ≤ p ≤ 109 ), where
r is the number of rows in the grid, c is the number of columns in the grid, and p is the maximum
value a timer can show.
Output
Output a single number, which is the expected time you have to wait if you make optimal decisions.
Your answer will be accepted if the absolute or relative error is within 10−6 of the judge’s answer.
Figure H.1: The first sample input after all mountains appear.
Input
The first line of input contains two integers q (1 ≤ q ≤ 2 · 105 ) and w (1 ≤ w ≤ 109 ), where q is
the number of queries and w is the width of the viewport. The viewport stretches from 0 to w.
Each of the next q lines contains two integers x (0 ≤ x ≤ w) and y (0 < y ≤ 109 ), the peak of
some mountain. If (x, y) is the peak of a mountain that is visible, that mountain will disappear.
Otherwise, that mountain will become visible.
Output
Output q lines. For each query in order, output a single line with a single number, which is the total
length of the bold lines rendered. Your answer will be accepted if the absolute or relative error is
within 10−6 of the judge’s answer.
Sample Explanation
In the first sample, the first two mountains intersect at the point (4.5, 0.5) The parts of the moun-
tains below that point are not rendered in bold.
In the second sample, the left mountain appears, then disappears, then appears again. The right
mountain appears and then disappears.
Input
The first line of input contains two integers n (1 ≤ n ≤ 40) and k (0 ≤ k ≤ 2,500), where n is the
length of the string and k is the number of not necessarily contiguous subsequences of NAC that
the output must contain.
The second line contains a string of length exactly n, consisting only of uppercase letters and/or
question marks.
Output
Output a string of upper case letters, replacing each question mark in the input string with an up-
percase letter so that the resulting string has exactly k subsequences of NAC. If this is not possible,
output -1. Any uppercase letters in the input string must be kept in their position. There may be
multiple possible solutions for any given test case; any correct solution will be accepted.
Input
The first line of input contains two integers n (1 ≤ n ≤ 105 ) and p (1 ≤ p ≤ 1018 ), where n is the
number of trips you have planned, and p is the number of pages in your new passport.
Each of the next n lines contains a single integer c (1 ≤ c ≤ 1018 ), which is the number of
contiguous pages which will need to be stamped for that trip.
Output
Output a single integer, which is the minimum number of trips you could possibly take before you
would need a new passport because there aren’t enough consecutive blank pages for your next trip.
Output n if you can take all trips, even in the worst case.
Now imagine moving the light source along the x-axis in the negative direction, effectively pulling
the light further away from all the objects in a straight line. As the light source moves, the shadows
move as well, potentially changing the number of shaded intervals on the wall. Your job is to
compute the sum of the lengths of the intervals along the x-axis for which the light source creates
a single shaded interval on the wall.
Output
Output a single number, which is the sum of the lengths of the intervals along the x-axis for which
the light source creates a single shaded interval on the wall. If this sum includes an unbounded
interval (i.e. there is a single shaded interval when the light source is infinitely far away), print −1
instead. Your answer will be accepted if the absolute or relative error is within 10−6 of the judge’s
answer.
Figure L.1: A solution to the third test case in the sample input.
Input
The first line of input contains a single integer t (1 ≤ t ≤ 20), which is the number of test cases.
Each of the next 4 · t lines describes t test cases, consisting of four triangles each, one triangle per
line. Each triangle consists of three integers a, b and c (1 ≤ a, b, c ≤ 107 ). Each of the integers is
equal to the square of the length of a side of a triangle. For example, if the three sides of a triangle
have lengths 3, 4 and 5, then the input would be 9 16 25. The integers will not necessarily be
perfect squares. It is guaranteed that the given triples each represent a triangle of positive area.
Input
The first line of input contains three integers n (1 ≤ n ≤ 5,000), i and t (0 ≤ i, t ≤ 109 ), where n
is the number of problems Tom has given Ashley, i is Ashley’s starting implementation skill level
and t is Ashley’s starting thinking skill level.
Each of the next n lines contains four integers ilow , ihigh (0 ≤ ilow ≤ ihigh ≤ 2 · 109 ), tlow , thigh
(0 ≤ tlow ≤ thigh ≤ 2 · 109 ). Each line describes a problem, where its implementation difficulty is
in the range [ilow , ihigh ] and its thinking difficulty is in the range [tlow , thigh ], each inclusive. Ashley
can only solve a problem if her current implementation skill levels falls within the implementation
difficulty range and her thinking skill level falls within the thinking difficulty range, each inclusive.
Output
Output a single integer, which is the maximum number of problems Ashley can solve if she chooses
her reflection after each solution optimally.