A15654 | Playoff
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
$2^n$ teams participate in a playoff tournament. The tournament consists of $2^n - 1$ games. They are held as follows: in the first phase of the tournament, the teams are split into pairs: team $1$ plays against team $2$ , team $3$ plays against team $4$ , and so on (so, $2^{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 $2^{n-1}$ teams remain. If only one team remains, it is declared the champion; otherwise, the second phase begins, where $2^{n-2}$ games are played: in the first one of them, the winner of the game " $1$ vs $2$ " plays against the winner of the game " $3$ vs $4$ ", then the winner of the game " $5$ vs $6$ " plays against the winner of the game " $7$ vs $8$ ", and so on. This process repeats until only one team remains.
The skill level of the $i$ -th team is $p_i$ , where $p$ is a permutation of integers $1$ , $2$ , ..., $2^n$ (a permutation is an array where each element from $1$ to $2^n$ occurs exactly once).
You are given a string $s$ which consists of $n$ characters. These characters denote the results of games in each phase of the tournament as follows:
- if $s_i$ is equal to 0, then during the $i$ -th phase (the phase with $2^{n-i}$ games), in each match, the team with the lower skill level wins;
- if $s_i$ is equal to 1, then during the $i$ -th phase (the phase with $2^{n-i}$ games), in each match, the team with the higher skill level wins.
Let's say that an integer $x$ is winning if it is possible to find a permutation $p$ such that the team with skill $x$ wins the tournament. Find all winning integers.
The skill level of the $i$ -th team is $p_i$ , where $p$ is a permutation of integers $1$ , $2$ , ..., $2^n$ (a permutation is an array where each element from $1$ to $2^n$ occurs exactly once).
You are given a string $s$ which consists of $n$ characters. These characters denote the results of games in each phase of the tournament as follows:
- if $s_i$ is equal to 0, then during the $i$ -th phase (the phase with $2^{n-i}$ games), in each match, the team with the lower skill level wins;
- if $s_i$ is equal to 1, then during the $i$ -th phase (the phase with $2^{n-i}$ games), in each match, the team with the higher skill level wins.
Let's say that an integer $x$ is winning if it is possible to find a permutation $p$ such that the team with skill $x$ wins the tournament. Find all winning integers.
输入格式
The first line contains one integer $n$ ( $1 \le n \le 18$ ).
The second line contains the string $s$ of length $n$ consisting of the characters 0 and/or 1.
The second line contains the string $s$ of length $n$ consisting of the characters 0 and/or 1.
输出格式
Print all the winning integers $x$ in ascending order.
输入输出样例
输入 #1
3 101
输出 #1
4 5 6 7
输入 #2
1 1
输出 #2
2
输入 #3
2 01
输出 #3
2 3
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted