Zio2024 Question Paper
Zio2024 Question Paper
Instructions to candidates
(b) N = 6
S = [ 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10,
11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 14, 14,
14, 14, 15, 15, 16, 16, 17, 17]
(c) N = 6
S = [ −19, −18, −16, −15, −14, −13, −12, −11, −11,
−11, −10, −10, −10, −9, −9, −8, −8, −7, −7,
−7, −6, −6, −6, −5, −5, −4, −4, −4, −3, −3,
−3, −3, −2, −2, −2, −2, −1, −1, −1, 0, 0, 1, 1, 1,
2, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 8, 9, 10, 11, 13, 14]
2
Problem 2
There are N pillars, numbered 1 to N . Each pillar i has height Hi , and is composed of
Hi stone slabs stacked on top of each other.
A sequence of pillars is called beautiful if the height of each pillar is one more than
the height of the previous pillar. For example, [3, 4, 5, 6, 7], [10, 11, 12, 13] and [4, 5] are
beautiful sequences, while [6, 5, 4, 3], [2, 4, 7, 9] and [1, 2, 3, 5, 4] are not beautiful.
You can perform the following operations on a sequence:
• Add one stone slab to pillar i. That is, increase Hi by 1.
• Remove one stone slab from pillar i, provided this does not remove all stone slabs
from the pillar. That is, reduce Hi by 1 if Hi > 1.
For each of the following sequences of pillars, find the minimum number of operations
required to make the sequence beautiful.
(a) N = 3
H = [2, 4, 6]
(b) N = 12
H = [1, 2, 3, 1, 1, 5, 1, 3, 5, 3, 11, 11]
(c) N = 20
H = [ 12, 21, 13, 9, 19, 17, 15, 18, 22, 19,
17, 19, 15, 20, 24, 17, 35, 25, 25, 29]
3
Problem 3
N nodes, numbered 0 to N − 1, are connected by N − 1 edges to form a tree. In a tree,
you can reach any node j from any node i via a unique sequence of edges.
The edges are denoted by a matrix P = [p1 , p2 , . . . , pN −1 ] which says that node pi is
connected to node i. Thus, if N = 3 and P = [2, 0], the set of nodes is [0, 1, 2] and P
says that node 2 is connected to node 1 and node 0 is connected to node 2.
You are also given a sequence of N − 1 edge weights W . If we fix an assignment of these
N − 1 edge weights to the N − 1 edges, we can define the distance dist(i, j) between any
pair of nodes i and j as the sum of the edge weights on the unique path from i to j.
Given an assignment of weights to the edges, the total distance of the tree is the sum of
the pairwise distances between the nodes. Formally, the total distance is
X
dist(i, j)
0≤i<j≤N −1
.
Our goal is to compute the maximum total distance among all possible assignments of
the given weights to the edges. Compute this quantity in the following cases.
(a) N = 5
P = [0, 0, 0, 1]
W = [1, 1, 1, 1]
(b) N = 10
P = [0, 1, 2, 3, 4, 5, 6, 7, 8]
W = [10, 12, 2, 3, 6, 5, 8, 9, 11]
(c) N = 15
P = [0, 0, 0, 1, 1, 2, 3, 4, 0, 6, 6, 6, 11, 11]
W = [9, 8, 19, 5, 6, 2, 2, 4, 5, 20, 25, 11, 15, 13]
4
Problem 4
There are N balls, B1 , B2 , . . . , BN . Each ball Bi has a colour Ci . The colours are not
necessarily distinct. For instance, we could have 3 balls with colours [red, blue, red].
We can form 2N subsets of balls. A subset is considered good if the balls in the subset
can be arranged in a line in at least one way such that no pair of adjacent balls are of
the same colour.
In each of the following situations, compute the number of good subsets. The balls are
listed in the order [B1 , B2 , . . . , BN ] in terms of their colour.
(b) N = 8
C = [red, red, red, green, green, green, blue, blue]
(c) N = 20
C = [ red, green, green, green, blue, blue, blue,
yellow, yellow, yellow, yellow, yellow, yellow,
purple, purple, purple, purple,
purple, purple, purple]