Zio 2023
Zio 2023
Instructions to candidates
Page 2
2. There are N students standing in a line. Every student has a badge with a number
from 1 to M . Different students can have the same badge number, and they can also
have different badge numbers. For all 1 ≤ i ≤ N , the ith number in array A represents
the badge number of the ith student from the left of the line.
You want to choose any subset of these students, such that there are exactly K distinct
badge numbers amongst the chosen students. Note that it is guaranteed that K ≤ M .
Note: A subset is any (not necessarily contiguous) selection of the students from the
line. Two subsets are considered different if there exists a student i who is present in
one subset but not in the other.
For each of the following values of N , M and A, calculate the number of subsets of
students you can choose such that there are exactly K distinct badge numbers amongst
the chosen students.
(a) N = 12, M = 4, K = 1, A = [1, 2, 1, 2, 1, 3, 2, 2, 3, 3, 1, 1]
(b) N = 20, M = 5, K = 3, A = [2, 2, 5, 5, 3, 3, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 1, 1, 4, 4]
(c) N = 25, M = 10, K = 6, A = [10, 8, 4, 1, 4, 10, 9, 3, 9, 2, 1, 7, 7, 1, 8, 6, 8, 10, 8, 4, 7, 10, 9, 5, 8]
Page 3
3. A permutation is a sequence of N integers from 1 to N containing each integer exactly
once. For example, [1, 3, 2, 4, 5] and [4, 2, 3, 1] are permutations, but [1, 3] and [2, 3, 4, 5]
are not.
There is a permutation P of length N . You are not given the permutation, but you are
given, for all 1 ≤ l ≤ r ≤ N , the index of the minimum element among Pl , Pl+1 , . . . , Pr .
The data is displayed in a triangle-like table. For example:
r
1 2 3
1 1 2 2
l 2 2 2
3 3
The element in the lth row and rth column of the table represents the index of the
minimum element among Pl , Pl+1 , . . . , Pr . For the above table, [2, 1, 3] is a valid per-
mutation that could be used to construct it:
However, this is not the only valid permutation. For example, [3, 1, 2] is also a valid
permutation that could have been used to construct the table. Given a table, you are
asked to find how many permutations could have been used to construct it. (In the
previous example, the answer is 2, as those are the only two permutations that could
have been used to construct the table.)
Page 4
(a) N = 4
r
1 2 3 4
1 1 2 3 3
2 2 3 3
l
3 3 3
4 4
(b) N = 8
r
1 2 3 4 5 6 7 8
1 1 1 1 1 5 5 5 5
2 2 2 2 5 5 5 5
3 3 3 5 5 5 5
4 4 5 5 5 5
l
5 5 5 5 5
6 6 7 7
7 7 7
8 8
(c) N = 15
r
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 1 2 2 4 4 4 4 4 4 4 4 4 4 14 14
2 2 2 4 4 4 4 4 4 4 4 4 4 14 14
3 3 4 4 4 4 4 4 4 4 4 4 14 14
4 4 4 4 4 4 4 4 4 4 4 14 14
5 5 5 5 8 9 10 10 10 10 14 14
6 6 7 8 9 10 10 10 10 14 14
7 7 8 9 10 10 10 10 14 14
l 8 8 9 10 10 10 10 14 14
9 9 10 10 10 10 14 14
10 10 10 10 10 14 14
11 11 11 13 14 14
12 12 13 14 14
13 13 14 14
14 14 14
15 15
Page 5
4. There are N stones, numbered from 1 to N . You are sequentially given M relations.
Each relation is of the form “Stone Ai weighs Xi units more than Stone Bi ”.
After each relation is added, you want to find an assignment of positive integer weights
to each of the N stones such that all relations added so far are satisfied. Note that
this is cumulative; once the third constraint is added, you must satisfy all of the first
three constraints. Out of all valid assignments, pick the one with the lowest total sum
of weights across all stones. Your answer for this step is the sum of weights in the
assignment. It is guaranteed that there will always be at least one valid assignment of
weights.
Your answer for the overall problem is the sum of weights over all steps.
For example, say that N = 3, M = 2, A = [1, 2], B = [2, 3], X = [5, 6]. The first relation
is “Stone 1 weighs 5 units more than Stone 2”. The optimal assignment satisfying this
relation is for Stone 1 to have weight 6 and Stones 2 and 3 to have weight 1, for a total
of 8. Note that the stones cannot have weight 0.
The second relation is “Stone 2 weighs 6 units more than Stone 3”. The optimal
assignment satisfying both relations is Stone 1 weight 12, Stone 2 weight 7, Stone 3
weight 1, for a total of 20. Summing both steps, the answer is 8 + 20 = 28.
(a) N = 10, M = 6,
A = [6, 5, 1, 2, 3, 3],
B = [2, 9, 10, 5, 2, 8],
X = [5, 4, 4, 1, 4, 2]
(b) N = 23, M = 22,
A = [11, 20, 12, 8, 20, 21, 5, 14, 7, 14, 21, 20, 23, 23, 23, 16, 11, 15, 11, 17, 11, 18],
B = [20, 12, 8, 13, 21, 5, 14, 7, 4, 19, 2, 23, 3, 9, 16, 1, 15, 10, 17, 6, 18, 22],
X = [16, 15, 16, 14, 13, 24, 18, 8, 17, 18, 12, 25, 21, 21, 12, 10, 23, 21, 3, 4, 12, 13]
(c) N = 30, M = 32
A = [18, 28, 27, 2, 21, 20, 12, 7, 13, 11, 30, 10, 2, 16, 7, 21, 16, 20, 6, 11, 16, 20, 15, 18, 11, 6, 27, 1, 2, 28, 2, 4]
B = [5, 3, 18, 1, 22, 29, 25, 9, 5, 8, 29, 12, 17, 19, 13, 26, 1, 10, 10, 14, 23, 29, 12, 21, 24, 3, 15, 8, 3, 12, 5, 3]
X = [2, 5, 5, 2, 2, 5, 5, 2, 1, 1, 5, 5, 3, 5, 1, 2, 4, 4, 4, 3, 2, 5, 1, 5, 4, 3, 13, 2, 5, 11, 4, 2]
Page 6