CF1767D.Playoff

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

2n2^n teams participate in a playoff tournament. The tournament consists of 2n−12^n - 1 games. They are held as follows: in the first phase of the tournament, the teams are split into pairs: team 11 plays against team 22, team 33 plays against team 44, and so on (so, 2n−12^{n-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 2n−12^{n-1} teams remain. If only one team remains, it is declared the champion; otherwise, the second phase begins, where 2n−22^{n-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.

The skill level of the ii-th team is pip_i, where pp is a permutation of integers 11, 22, ..., 2n2^n (a permutation is an array where each element from 11 to 2n2^n occurs exactly once).

You are given a string ss which consists of nn characters. These characters denote the results of games in each phase of the tournament as follows:

  • if sis_i is equal to 0, then during the ii-th phase (the phase with 2n−i2^{n-i} games), in each match, the team with the lower skill level wins;
  • if sis_i is equal to 1, then during the ii-th phase (the phase with 2n−i2^{n-i} games), in each match, the team with the higher skill level wins.

Let's say that an integer xx is winning if it is possible to find a permutation pp such that the team with skill xx wins the tournament. Find all winning integers.

2n2^n 支队伍参加一场淘汰制锦标赛。该锦标赛共进行 2n−12^n - 1 场比赛,赛程安排如下:在锦标赛的第一阶段,所有队伍被两两配对:第 11 队对阵第 22 队,第 33 队对阵第 44 队,依此类推(因此该阶段共进行 2n−12^{n-1} 场比赛)。每场比赛的负方被淘汰,且每场比赛必有一支队伍被淘汰(无平局)。经过该阶段后,仅剩 2n−12^{n-1} 支队伍。若此时仅剩一支队伍,则该队被宣布为冠军;否则进入第二阶段,该阶段共进行 2n−22^{n-2} 场比赛:首场比赛由“第 11 队 vs 第 22 队”的胜者对阵“第 33 队 vs 第 44 队”的胜者,接着由“第 55 队 vs 第 66 队”的胜者对阵“第 77 队 vs 第 88 队”的胜者,依此类推。该过程持续进行,直至仅剩一支队伍。

第 ii 支队伍的实力值为 pip_i,其中 pp 是整数 1,2,…,2n1, 2, \dots, 2^n 的一个排列(即数组中 11 至 2n2^n 的每个整数恰好出现一次)。

给定一个长度为 nn 的字符串 ss,其字符表示锦标赛各阶段的比赛结果,规则如下:

  • 若 si=0s_i = 0,则在第 ii 阶段(该阶段共进行 2n−i2^{n-i} 场比赛)的每一场比赛中,实力值较低的队伍获胜;
  • 若 si=1s_i = 1,则在第 ii 阶段(该阶段共进行 2n−i2^{n-i} 场比赛)的每一场比赛中,实力值较高的队伍获胜。

我们称一个整数 xx 是可获胜的(winning),如果存在某个排列 pp,使得实力值为 xx 的队伍最终赢得整个锦标赛。请找出所有可获胜的整数。

输入格式

The first line contains one integer nn (1≤n≤181 \le n \le 18).

The second line contains the string ss of length nn consisting of the characters 0 and/or 1.

第一行包含一个整数 nn(1≤n≤181 \le n \le 18)。

第二行包含一个长度为 nn 的字符串 ss,由字符 0 和/或 1 组成。

输出格式

Print all the winning integers xx in ascending order.

按升序输出所有获胜整数 xx。

输入输出样例

  • 输入#1

    3
    101

    输出#1

    4 5 6 7
  • 输入#2

    1
    1

    输出#2

    2
  • 输入#3

    2
    01

    输出#3

    2 3

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

首页