AtCoder Regular Contest++ 221
D
两棵平衡子树
Two Balanced Subtrees
AtCoder
⌀ 2946
原题
← CE →

两棵平衡子树AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

You are given a positive integer $N$.

给定一个正整数 $N$。AI (CI翻译)

There is a complete binary tree with $2^N-1$ vertices. The vertices are numbered $1$ through $2^N-1$.

有一棵包含 $2^N-1$ 个顶点的完全二叉树。顶点编号为 $1$ 到 $2^N-1$。AI (CI翻译)

Vertex $1$ is the root, and for each $i\ (1\leq i\lt 2^{N-1})$, vertex $i$ has vertices $2i$ and $2i+1$ as its children.

顶点 $1$ 是根。对于每个 $i\ (1\leq i\lt 2^{N-1})$,顶点 $i$ 的两个子节点分别为顶点 $2i$ 和 $2i+1$。AI (CI翻译)

Find one way to write an integer between $1$ and $2^N-1$, inclusive, on the vertices (where all $2^N-1$ written integers are distinct) such that the following condition is satisfied.

请在各个顶点上分别写入一个 $1$ 到 $2^N-1$ 之间(包含边界)的整数,且所有 $2^N-1$ 个写入的整数互不相同,使其满足以下条件:AI (CI翻译)

  • For each $i\ (1\leq i\lt 2^{N-1})$, the absolute difference between the sum of the integers written on the vertices of the subtree rooted at vertex $2i$ and the sum of the integers written on the vertices of the subtree rooted at vertex $2i+1$ is $1$.
  • 对于每个 $i\ (1\leq i\lt 2^{N-1})$,以顶点 $2i$ 为根的子树中各顶点所写整数之和,与以顶点 $2i+1$ 为根的子树中各顶点所写整数之和的绝对差为 $1$。
AI (CI翻译)

It can be proved that there always exists a way to write the integers satisfying the condition under the constraints of this problem.

可以证明,在本题约束条件下,总能找到满足条件的整数写法。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $2\leq N\leq 18$
  • All input values are integers.
  • $2\leq N\leq 18$
  • 所有输入值均为整数。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

N

N
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Let $P_i$ be the integer written on vertex $i$. Output:

设 $P_i$ 表示写在顶点 $i$ 上的整数。请按以下格式输出:AI (CI翻译)

P_1 P_2 \ldots P_{2^N-1}

P_1 P_2 \ldots P_{2^N-1}
AI (CI翻译)

$(P_1,P_2,\ldots,P_{2^N-1})$ must be a permutation of $(1,2,\ldots,2^N-1)$.

$(P_1,P_2,\ldots,P_{2^N-1})$ 必须是 $(1,2,\ldots,2^N-1)$ 的一个排列。AI (CI翻译)

If there are multiple valid ways to write the integers, any of them will be accepted.

如果有多种满足条件的写法,输出其中任意一种即可。AI (CI翻译)

样例

Input #1
3
Output #1
1 7 2 3 4 5 6
We can verify that this assignment satisfies the condition, as follows. - $i=1$: The sum of the integers written on the vertices of the subtree rooted at vertex $2$ is $14$, the sum of the integers written on the vertices of the subtree rooted at vertex $3$ is $13$, and $|14-13|=1$. - $i=2$: The sum of the integers written on the vertices of the subtree rooted at vertex $4$ is $3$, the sum of the integers written on the vertices of the subtree rooted at vertex $5$ is $4$, and $|3-4|=1$. - $i=3$: The sum of the integers written on the vertices of the subtree rooted at vertex $6$ is $5$, the sum of the integers written on the vertices of the subtree rooted at vertex $7$ is $6$, and $|5-6|=1$.
题目信息
题号
arc221_d
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。