Playoff Restoration solution codeforces
teams participate in a playoff tournament. The tournament consists of games. They are held as follows: first of all, the teams are split into pairs: team plays against team , team plays against team (exactly in this order), and so on (so, games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only teams remain. If only one team remains, it is declared the champion; otherwise, games are played: in the first one of them, the winner of the game “ vs ” plays against the winner of the game “ vs “, then the winner of the game “ vs ” plays against the winner of the game “ vs “, and so on. This process repeats until only one team remains.
After the tournament ends, the teams are assigned places according to the tournament phase when they were eliminated. In particular:
- the winner of the tournament gets place ;
- the team eliminated in the finals gets place ;
- both teams eliminated in the semifinals get place ;
- all teams eliminated in the quarterfinals get place ;
- all teams eliminated in the 1/8 finals get place , and so on.
For example, this picture describes one of the possible ways the tournament can go with, and the resulting places of the teams:
Unfortunately, due to a system crash, almost all tournament-related data was lost. The only pieces of data that remain are the values of, and . You are asked to restore the resulting placing of the teams in the tournament, if it is possible at all.
The only line contains three integers, and ( ; ; ).
If it is impossible to find any placing of the teams that is consistent with the data you have, print one integer.
Otherwise, printintegers, where -th integer should be equal to (the place of the -th team). Note that your answer should be consistent with one of the possible ways the tournament could go, and note that the initial structure of the tournament is fixed (for example, teams and always play in the first phase of the tournament against each other). If there are multiple ways to restore the places of the teams which are consistent with the data you have, print any of them.
3 1337 75275197
5 3 5 2 1 5 5 3
2 100 5040100
1 3 3 2
2 100 7020100
The tournament for the first example is described in the statement.
For the third example, the placing(team gets place , team gets place , teams and get place ) could result in a hash value of with , but no tournament can result in such placing since teams and play against each other in the semifinals, so they cannot get two first places.
Solution: Click here
Also read : Airline Restrictions codechef solution