CF1569E.Playoff Restoration

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

2k2^k teams participate in a playoff tournament. The tournament consists of 2k−12^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 11 plays against team 22, team 33 plays against team 44 (exactly in this order), and so on (so, 2k−12^{k-1} 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 2k−12^{k-1} teams remain. If only one team remains, it is declared the champion; otherwise, 2k−22^{k-2} games are played: in the first one of them, the winner of the game "11 vs 22" plays against the winner of the game "33 vs 44", then the winner of the game "55 vs 66" plays against the winner of the game "77 vs 88", 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 11;
  • the team eliminated in the finals gets place 22;
  • both teams eliminated in the semifinals get place 33;
  • all teams eliminated in the quarterfinals get place 55;
  • all teams eliminated in the 1/8 finals get place 99, and so on.

For example, this picture describes one of the possible ways the tournament can go with k=3k = 3, and the resulting places of the teams:

After a tournament which was conducted by the aforementioned rules ended, its results were encoded in the following way. Let pip_i be the place of the ii-th team in the tournament. The hash value of the tournament hh is calculated as h=(∑i=12ki⋅Api) mod 998244353h = (\sum \limits_{i=1}^{2^k} i \cdot A^{p_i}) \bmod 998244353, where AA is some given integer.

Unfortunately, due to a system crash, almost all tournament-related data was lost. The only pieces of data that remain are the values of kk, AA and hh. You are asked to restore the resulting placing of the teams in the tournament, if it is possible at all.

2k2^k 支队伍参加一场淘汰制锦标赛。该锦标赛共进行 2k−12^k - 1 场比赛,赛程安排如下:首先将所有队伍两两分组:第 11 支队伍对阵第 22 支队伍,第 33 支队伍对阵第 44 支队伍(严格按此顺序),依此类推(因此该阶段共进行 2k−12^{k-1} 场比赛)。每场比赛中失败的队伍即被淘汰,且每场比赛恰好淘汰一支队伍(不存在平局)。该阶段结束后,仅剩 2k−12^{k-1} 支队伍。若只剩一支队伍,则其被宣布为冠军;否则继续进行 2k−22^{k-2} 场比赛:第一场由“第 11 场 vs 第 22 场”的胜者对阵“第 33 场 vs 第 44 场”的胜者,第二场由“第 55 场 vs 第 66 场”的胜者对阵“第 77 场 vs 第 88 场”的胜者,依此类推。该过程不断重复,直至仅剩一支队伍。

锦标赛结束后,各支队伍依据其被淘汰所处的轮次获得相应名次。具体规则如下:

  • 锦标赛冠军(最终胜者)获得第 11 名;
  • 在决赛中被淘汰的队伍获得第 22 名;
  • 在半决赛中被淘汰的两支队伍均获得第 33 名;
  • 在四分之一决赛中被淘汰的所有队伍均获得第 55 名;
  • 在八分之一决赛中被淘汰的所有队伍均获得第 99 名,依此类推。

例如,下图描述了当 k=3k = 3 时锦标赛的一种可能进行方式,以及各支队伍最终获得的名次:

在一场按上述规则进行的锦标赛结束后,其结果以如下方式编码:设 pip_i 表示第 ii 支队伍在锦标赛中获得的名次,则锦标赛的哈希值 hh 定义为

h=(∑i=12ki⋅Api) mod 998244353,h = \left(\sum_{i=1}^{2^k} i \cdot A^{p_i}\right) \bmod 998244353,

其中 AA 是给定的某个整数。

不幸的是,由于系统崩溃,几乎所有与锦标赛相关的数据均已丢失。目前仅存的数据为 kk、AA 和 hh 的值。你的任务是根据这些信息,还原出锦标赛中各支队伍的最终名次(即序列 p1,p2,…,p2kp_1, p_2, \dots, p_{2^k}),如果该还原是可能的话。

输入格式

The only line contains three integers kk, AA and hh (1≤k≤51 \le k \le 5; 100≤A≤108100 \le A \le 10^8; 0≤h≤9982443520 \le h \le 998244352).

唯一一行包含三个整数 kk、AA 和 hh(1≤k≤51 \le k \le 5;100≤A≤108100 \le A \le 10^8;0≤h≤9982443520 \le h \le 998244352)。

输出格式

If it is impossible to find any placing of the teams that is consistent with the data you have, print one integer −1-1.

Otherwise, print 2k2^k integers, where ii-th integer should be equal to pip_i (the place of the ii-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 11 and 22 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.

如果无法找到任何一种队伍排名方式,使其与你所拥有的数据一致,则输出一个整数 −1-1。

否则,输出 2k2^k 个整数,其中第 ii 个整数应等于 pip_i(即第 ii 支队伍的名次)。注意:你的答案必须与某一种可能的锦标赛进行过程一致,且锦标赛的初始结构是固定的(例如,队伍 11 和队伍 22 总是在锦标赛第一轮中相互对阵)。如果存在多种满足已有数据的队伍名次恢复方案,请输出其中任意一种。

输入输出样例

  • 输入#1

    3 1337 75275197

    输出#1

    5 3 5 2 1 5 5 3
  • 输入#2

    2 100 5040100

    输出#2

    1 3 3 2
  • 输入#3

    2 100 7020100

    输出#3

    -1

说明/提示

The tournament for the first example is described in the statement.

For the third example, the placing [1,2,3,3][1, 2, 3, 3] (team 11 gets place 11, team 22 gets place 22, teams 33 and 44 get place 33) could result in a hash value of 70201007020100 with A=100A = 100, but no tournament can result in such placing since teams 11 and 22 play against each other in the semifinals, so they cannot get two first places.

第一个示例所描述的锦标赛已在题干中给出。

对于第三个示例,名次排列 [1,2,3,3][1, 2, 3, 3](即队伍 11 获得第 11 名,队伍 22 获得第 22 名,队伍 33 和 44 并列第 33 名)在 A=100A = 100 时可能产生哈希值 70201007020100,但没有任何锦标赛能产生该名次排列,因为队伍 11 和 22 在半决赛中相互对阵,故它们不可能分别获得第 11 名和第 22 名。

输入解题思路,AI测评打分。不知道怎么写?

首页