Many prizes
Time limit5sMemory limit512 MB
In a Swiss tournament of 2^N teams where the lower number always wins, find the largest team ranked top P under every seeding and under some seeding.
- Level
Hard8 of 10
- Topics
- Combinatorics, Math, Greedy
- Solved
- No attempts yet
Problem
You run a tournament with teams. The teams that finish in ranks 0 through each receive one identical prize.
The teams are numbered 0 through . When team plays team , team wins if and only if .
An ordering of all teams in a single line is called a tournament list. The tournament list decides which teams meet and when.
Find two numbers. First, the largest-numbered team that wins a prize no matter how the tournament list is ordered. Second, the largest-numbered team that wins a prize for at least one ordering of the tournament list.
How the tournament runs
The tournament has rounds.
Each team carries a record, the results of its games so far in order. For example, a team that has played three games and won the first, lost the second and won the third has record [W, L, W]. A team that has played no games has record [].
In every round each team plays one game against a team with the same record. Among the teams with a given record, the first and the second in the tournament list meet, the third and the fourth meet, and so on.
After rounds every team has a different record. Records are compared lexicographically with W ahead of L, and a larger record gets a better rank, so [W, W, W] > [W, W, L] > [W, L, W] > ... > [L, L, L].
Here is a tournament with and the tournament list [2, 4, 5, 3, 6, 7, 1, 0]. Each column is one round, teams are grouped by their record, and the winner of each game is marked with *. The last column is the final ranking, best rank on top.
R1 R2 R3 Final
[] [W] [W,W]
2 * 2 * 2 0 [W,W,W]
4 3 0 * 2 [W,W,L]
[W,L]
5 6 3 * 3 [W,L,W]
3 * 0 * 6 6 [W,L,L]
[L] [L,W]
6 * 4 * 4 1 [L,W,W]
7 5 1 * 4 [L,W,L]
[L,L]
1 7 5 * 5 [L,L,W]
0 * 1 * 7 7 [L,L,L]
With and , the prizes go to teams 0, 2, 3 and 6.
For and , the largest-numbered team that wins a prize regardless of the tournament list is team 0. The list above shows that team 1 can miss a prize, and team 0 wins one under every ordering.
For and , the largest-numbered team that can win a prize for some tournament list is team 6. The list above shows team 6 winning a prize, and team 7 never wins one under any ordering.
Input
The first line contains the number of test cases . test cases follow. Each test case is two space separated integers and : the tournament has teams and prizes.
Limits
Output
For each test case, print one line in the form Case #x: y z. Here is the test case number starting from 1, is the largest-numbered team that wins a prize regardless of the tournament list, and is the largest-numbered team that wins a prize for at least one tournament list.