0% found this document useful (0 votes)
23 views

CSEC-ASTU Competitive Programming Contest 2021: Problem 91

This document describes a cup competition problem. It involves N rounds with 2N teams numbered 0 to 2N-1. In each round, the lower numbered team wins. This determines which teams a given team X beat and lost to. The problem is to find the optimistic and pessimistic rankings (from 1 to 2N) that X could achieve given the round structure and results. The input provides N and a team X, and the output gives the optimistic and pessimistic rankings for that team.

Uploaded by

Abraham Mekuria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

CSEC-ASTU Competitive Programming Contest 2021: Problem 91

This document describes a cup competition problem. It involves N rounds with 2N teams numbered 0 to 2N-1. In each round, the lower numbered team wins. This determines which teams a given team X beat and lost to. The problem is to find the optimistic and pessimistic rankings (from 1 to 2N) that X could achieve given the round structure and results. The input provides N and a team X, and the output gives the optimistic and pessimistic rankings for that team.

Uploaded by

Abraham Mekuria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSEC-ASTU

CSEC-ASTU Competitive Programming Contest 2021

Problem 91: The Eurocup is Here!


Time Limit: 3 second

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

CSEC-ASTU Competitive Programming Contest 2021

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.

Sample Input 1 Sample Output 1


4 28
31 3 15
4 10 23
22 5 16
4 15

You might also like