NCPC 2020 Problems
NCPC 2020 Problems
NCPC 2020 Problems
NCPC 2020
November 7, 2020
Problems
A Array of Discord
B Big Brother
C Coin Stacks
D Dams in Distress
E Exhaustive Experiment
F Film Critics
G Gig Combinatorics
H Hiring and Firing
I Infection Estimation
J Joining Flows
K Keep Calm And Carry Off
L Language Survey
M Methodic Multiplication
Input
The first line of input contains n (2 ≤ n ≤ 100), the length of Zeus’ answer. The second line
contains n integers a1 , a2 , . . . , an (0 ≤ a1 ≤ a2 ≤ . . . ≤ an ≤ 1015 ), Zeus’ answer.
Output
If Eris can make the list not be sorted by changing a single digit of one of the numbers, then
output n integers b1 , . . . , bn , the resulting list of numbers after making the change. Otherwise,
output “impossible”. If there are many valid solutions, any one will be accepted.
Figure B.1: Illustration of Sample Input 3. The blue shaded area in the middle indicates the
region where the camera can be placed.
Input
The first line of input contains an integer n (3 ≤ n ≤ 500 000), the number of vertices describing
the polygon representing the office floor. Then follow n lines containing the integer coordinates
x, y of the polygon in clockwise order (0 ≤ x, y ≤ 107 ).
Output
Output the area of the region of the map where a CCTV camera could be placed so that the rest
of the office can be observed. (If it is not possible to put the camera anywhere, this area is 0.)
The answer must be correct with a relative of at most 10−6 , or an absolute error of at most
0.1.
Input
The first line of input contains an integer n (2 ≤ n ≤ 50), the number of coin stacks. Then
follows a line containing n nonnegative integers a1 , a2 , . . . , an , where ai is the number of coins
in the i’th stack. The total number of coins is at most 1 000.
Output
If the players can win the game, output a line containing “yes”, followed by a description
of the moves. Otherwise output a line containing “no”. When describing the moves, output
one move per line, each move being described by two distinct integers a and b (between 1 and
n) indicating that the players remove a coin from stacks a and b. If there are several possible
solutions, output any one of them.
48/50 10/49
0/50
50/100
Figure D.1: Illustration of Sample Input 1. In this case Freyr only has to make 2 units of rain
at the left-most dam in order to make it break and send 50 units of water downstream, which
then ultimately results in 100 units of rain reaching the war camp, well exceeding the 75 units of
water needed to flood the camp.
Output
Output the minimum amount of rain Freyr needs to make at one location, which will result in at
least w water reaching the war camp.
trigger a positive reading. For each unit distance the helium has
risen it will also have expanded by one unit. Thus the leak test will produce a positive result
if the tested component is leaking or if there is a leaking component above it for which the x
coordinates differs by at most half of the difference in the y coordinate. See Figure E.1 for an
example.
You start out with a positive mindset thinking that there are probably just a few leaking
components responsible for all the positive measurements. To determine if this is indeed possible
you set out to determine the minimum number of leaking components that could give rise to the
observed leak test results.
y
N
P
x
- P
Figure E.1: Illustration of Sample Input 1. Circles indicate components and the blue triangle
indicates where helium will spread when the first component is tested. This test being positive
means that at least one of the the three components covered by the triangle is leaking. The
correct answer in this case is 1 since the measurement results can all be explained with only the
rightmost component leaking.
Output
Output a single integer, the minimum number of leaking components that could give rise to the
observed leak test results. If no set of leaking components could give rise to the observed results,
instead output the single word impossible.
Input
The first line of input contains three integers n, m and k (1 ≤ n ≤ 2 · 105 , 1 ≤ m ≤ 104 ,
0 ≤ k ≤ n · m). The second line contains the n integers a1 , a2 , . . . , an (0 ≤ ai ≤ m for each i),
the n critic scores as described above.
Output
If the critics can be ordered in such a way that the resulting average score is exactly k/n, then
output n integers p1 , . . . , pn , where 1 ≤ pi ≤ n indicates that the ith critic to visit the cinema is
the critic numbered pi . This list of integers should be a permutation such that the average score
given by the critics is k/n. If there are multiple solutions any one will be accepted.
Otherwise, if there is no such way to order the critics, output “impossible”.
Input
The first line of the input consists of a single integer n (1 ≤ n ≤ 106 ), the number of songs Tóti
has written. The second line consists of n integers, each in {1, 2, 3}, giving the hype-ratings of
the n songs in the order they were written.
Output
The output should consist of one integer, the number of setlists Tóti can make. Since this number
can be large, print it modulo 109 + 7.
Input
The first line of input contains an integer n (1 ≤ n ≤ 105 ), the length in days of the foreseeable
future. Then follow n lines, the ith of which contains two integers fi and hi (0 ≤ fi , hi ≤ 106 )
where fi is the number of workers fired on day i and hi the number of people hired.
The number of workers fired Pon a day is never larger than the number of currently employed
i−1
workers (in other words, fi ≤ j=0 hj − fj for all 1 ≤ i ≤ n).
Output
Output a line with an integer k, the smallest number of HR people needed. The HR people are
arbitrarily given IDs from 1 to k. Then output a line with n integers, the ith of which contains
the ID of the HR person in charge of the firing and hiring on day i. If there is more than one
solution, any one will be accepted.
Interaction
Your program can run up to 50 tests, and must then produce an estimate of the number of
infected people. To issue a test, output “test k” for an integer 1 ≤ k ≤ 107 . The judge will
then provide a line which contains either “1” if the test for k randomly chosen people came
back positive, or “0” if it came back negative. The k people will be chosen without replacement,
i.e., the same person cannot be chosen twice. However, the tests are independent, so a person
may end up being chosen in more than one round.
To provide the estimate, output “estimate x”, where 0 ≤ x ≤ 107 is your estimate on the
number of infected people. The answer will be treated as correct if it is within a factor 2 of the
correct answer y, i.e., if y/2 ≤ x ≤ 2y.
There will be a total of 100 runs of your program. You may assume that each run is
deterministic: making the same sequence of tests on the ith run will always result in the same
sequence of test results. To facilitate testing of your solutions, we provide a simple tool that you
can download from the Kattis page for this problem. Remember to flush your standard output
buffer for every line you output!
Input
The first line of input contains an integer k (1 ≤ k ≤ 10), the number of taps. Then follow
k lines, describing the taps. The i’th of these lines contains the three integers ti , ai , and bi
(0 ≤ ti ≤ 106 , 0 ≤ ai ≤ bi ≤ 106 ) describing the i’th faucet.
Next follows a line containing an integer r (1 ≤ r ≤ 105 ), the number of new recipies to
check. Then follows r lines, each describing a recipe. A recipe is described by two integers
τ and φ (0 ≤ τ ≤ 106 and 1 ≤ φ ≤ 106 ), where τ is the chocolate temperature and φ the
chocolate flow needed for this recipe.
Output
For each of the r recipies, print one line with the string “yes” if it is possible to achieve the
desired combination of chocolate temperature and flow, and “no” otherwise.
Input
The input consists of two lines, each containing a positive integer with at most 106 digits. These
are the two integers Petra wants to add.
Output
Output a single integer, the minimum number of times Petra must add 1 to one of her numbers
(while subtracting 1 from the other) until they can be added using the standard addition algorithm
without any carry digits.
Input
The first line of input contains two integers n and m (1 ≤ n, m ≤ 200).
The following n lines each contain a string of length m, consisting of the characters 1 and 2.
The jth character on the ith line is 1 if exactly one language is spoken in that cell, and 2 if at
least two languages are spoken.
Output
If the languages can be divided according to the information, then output three copies of the grid.
The first copy should consist of characters “A” and “.”, where the “A” indicates that Arwegian is
spoken in that cell, and “.” indicates that it isn’t spoken. The following two grids should consist
of characters “B” and “.”, and “C” and “.”, respectively, with the corresponding information
about Banish and Cwedish.
Remember that the three regions have to be connected and non-empty, and every cell must be
part of some region. For readability, it is recommended to put empty lines in between the three
grids, but it is not necessary to do so. If there are multiple solutions any one will be accepted.
Otherwise, if there is no way to divide the languages, output “impossible”.
....
...C
CCCC
S(S(0)), S(S(S(0))), and so on. With these two symbols, the operations
of addition and multiplication are defined inductively by the following axioms: for any natural
numbers x and y, we have
x+0=x x·0=0
x + S(y) = S(x + y) x · S(y) = x · y + x
The two axioms on the left define addition, and the two on the right define multiplication.
For instance, given x = S(S(0)) and y = S(0) we can repeatedly apply these axioms to
derive
Write a program which given two natural numbers x and y, defined in Peano arithmetic, computes
the product x · y.
Input
The input consists of two lines. Each line contains a natural number defined in Peano arithmatic,
using at most 1 000 characters.
Output
Output the product of the two input numbers.