CSEC-ASTU Competitive Programming Contest 2021: Problem 91
CSEC-ASTU Competitive Programming Contest 2021: Problem 91
We are the champions of the Eurocup! Well …almost. Actually, we lost in first round and didn’t win any
match. But we were beaten by the real champions so, optimistically, we could be the second! Cup
competitions are always unfair …
Let’s consider a cup competition, that consists of N rounds where 2N teams take part. The winners of each
round proceed to the next round. So in round 1 there are 2N teams, in round 2 there are 2N−1 teams, and
so on. Teams are numbered 0, 1, 2, . . . , 2N − 1. The matches in each round are scheduled according to
this order. Assume that, when two teams play, the one with the lowest number always wins. In conclusion,
in round 1 the matches are: (0 vs. 1), (2 vs. 3), (4 vs.5), …; in round 2: (0 vs. 2), (4 vs. 6), …The situation for
N = 3 is shown in the picture below.
A team, X, is better than all the teams it has beaten, and it is worse than all the teams it has lost with.
Moreover, we can apply a sort of transitivity: X is better than all the team that are worse than the teams
that are worse than X; and X is worse than the teams that are better than the teams that are better than
X. For example, in the case of N = 3, team 7 is worse than 6, 4 and 0.
When the competition is finished, all teams are given a ranking from 1 to 2N (different for each team, 1
for the winner, 2 for the subchampion, etc.). The ranking of team X is R(X). A valid ranking has the
following property: if X is better than Y , then R(X) < R(Y ). Obviously, there are many possible valid rankings
(because there are pairs of teams that we have no information between them). We define the optimistic
classification of a team X as the smallest value of R(X) for any valid ranking R. Similarly, the pessimistic
classification of X is the biggest value of R(X) for any valid ranking R.
CSEC-ASTU
Given the number of rounds, N, and the number of a team, X, you have to compute the optimistic and
pessimistic classification of X.
Input
The first line of the input contains an integer M, indicating the number of test cases. Each test case consists
of two integers N and X. N is the total number of rounds in the competition (0 < N < 31), and X is the
number of a team (0 ≤ X ≤ 2N − 1).
Output
For each test case, the output should consist of a single line with two integers: the optimistic and the
pessimistic classification of the corresponding team.