CF1837E.Playoff Fixing

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

2k2^k teams participate in a playoff tournament. The teams are numbered from 11 to 2k2^k, in order of decreasing strength. So, team 11 is the strongest one, team 2k2^k is the weakest one. A team with a smaller number always defeats a team with a larger number.

First of all, the teams are arranged in some order during a procedure called seeding. Each team is assigned another unique value from 11 to 2k2^k, called a seed, that represents its starting position in the playoff.

The tournament consists of 2k−12^k - 1 games. They are held as follows: the teams are split into pairs: team with seed 11 plays against team with seed 22, team with seed 33 plays against team with seed 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.

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 "seed 11 vs seed 22" plays against the winner of the game "seed 33 vs seed 44", then the winner of the game "seed 55 vs seed 66" plays against the winner of the game "seed 77 vs seed 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.

Now that we established the rules, we do a little rigging. In particular, we want:

  • team 11 (not team with seed 11) to take place 11;
  • team 22 to take place 22;
  • teams 33 and 44 to take place 33;
  • teams from 55 to 88 to take place 55, 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:

Some seeds are already reserved for some teams (we are not the only ones rigging the tournament, apparently). We have to fill the rest of the seeds with the remaining teams to achieve the desired placements. How many ways are there to do that? Since that value might be large, print it modulo 998 244 353998\,244\,353.

2k2^k 支队伍参加一场淘汰制锦标赛。这些队伍按实力从强到弱编号为 11 到 2k2^k:即队伍 11 实力最强,队伍 2k2^k 实力最弱。编号更小的队伍总是击败编号更大的队伍。

首先,在一个称为“抽签”(seeding)的过程中,队伍被以某种顺序排列。每支队伍被分配一个 11 到 2k2^k 之间的唯一整数,称为“种子号”(seed),表示其在锦标赛中的初始位置。

该锦标赛共进行 2k−12^k - 1 场比赛,规则如下:队伍被两两配对——种子号为 11 的队伍对阵种子号为 22 的队伍,种子号为 33 的队伍对阵种子号为 44 的队伍(严格按此顺序),依此类推(因此该轮共进行 2k−12^{k-1} 场比赛)。一场比赛失利的队伍即被淘汰。

此后仅剩 2k−12^{k-1} 支队伍。若仅剩一支队伍,则其被宣布为冠军;否则继续进行 2k−22^{k-2} 场比赛:第一场由“种子 11 对种子 22”的胜者对阵“种子 33 对种子 44”的胜者,第二场由“种子 55 对种子 66”的胜者对阵“种子 77 对种子 88”的胜者,依此类推。该过程不断重复,直至仅剩一支队伍。

锦标赛结束后,各队伍的最终名次根据其被淘汰所处的轮次确定。具体规则如下:

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

在明确上述规则后,我们着手进行一些“操控”。具体而言,我们希望实现以下名次安排:

  • 队伍 11(注意:不是种子号为 11 的队伍)获得第 11 名;
  • 队伍 22 获得第 22 名;
  • 队伍 33 和 44 均获得第 33 名;
  • 队伍 55 至 88 均获得第 55 名,依此类推。

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

某些种子号已被预先指定给特定队伍(显然,我们并非唯一操控锦标赛的人)。我们需要将剩余的种子号分配给其余队伍,以达成上述期望的名次安排。问:有多少种合法的分配方式?由于答案可能很大,请输出其对 998 244 353998\,244\,353 取模的结果。

输入格式

The first line contains a single integer kk (0≤k≤190 \le k \le 19) — there are 2k2^k teams.

The second line contains 2k2^k integers a1,a2,…,a2ka_1, a_2, \dots, a_{2^k} (ai=−1a_i = -1 or 1≤ai≤2k1 \le a_i \le 2^k). If ai≠−1a_i \ne -1, then team aia_i has seed ii. Otherwise, the seed ii is not reserved for any team.

All values, that are not −1-1, are distinct.

第一行包含一个整数 kk(0≤k≤190 \le k \le 19)——共有 2k2^k 支队伍。

第二行包含 2k2^k 个整数 a1,a2,…,a2ka_1, a_2, \dots, a_{2^k}(每个 aia_i 为 −1-1 或满足 1≤ai≤2k1 \le a_i \le 2^k)。若 ai≠−1a_i \ne -1,则表示队伍 aia_i 获得第 ii 号种子;否则,第 ii 号种子未被任何队伍保留。

所有不为 −1-1 的 aia_i 值互不相同。

输出格式

Print a single integer — the number of ways to fill the non-reserved seeds so that the tournament goes as planned, modulo 998 244 353998\,244\,353.

输出一个整数——即填充非保留种子的方式数目,使得锦标赛按计划进行,结果对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    2
    1 2 3 4

    输出#1

    0
  • 输入#2

    2
    1 3 4 2

    输出#2

    1
  • 输入#3

    1
    -1 -1

    输出#3

    2
  • 输入#4

    2
    -1 -1 -1 -1

    输出#4

    16
  • 输入#5

    3
    -1 -1 -1 -1 2 -1 -1 -1

    输出#5

    768
  • 输入#6

    0
    1

    输出#6

    1

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

首页