QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 256 MB Puntuación total: 100 Hackeable ✓

#9602. 新手魔法师

Estadísticas

小狐狸 HoshiYo 是一位刚进入魔法学校的魔法师。作为一名新手,他不擅长许多种类的魔法,尤其是与数字相关的魔法。

有一天,HoshiYo 学习了一种可以改变长度为 $2^n$ 的数组中整数的魔法。然而,由于不够熟练,他每次使用魔法时只能改变数组中一半的整数。形式化地,设数组为 $a_0, a_1, \dots, a_{2^n-1}$,使用一次魔法可以执行以下操作:

  • 选择数组中 $2^{n-1}$ 个不同的整数和一个整数 $x$(可能是负数),将 $x$ 加到其中一个数上,将 $x+2$ 加到另一个数上,将 $x+4$ 加到另一个数上,以此类推,直到将 $x + 2^n - 2$ 加到最后一个数上。换句话说,选择 $2^{n-1}$ 个不同的下标 $p_0, p_1, \dots, p_{2^{n-1}-1}$(下标范围为 $0$ 到 $2^n - 1$),对于每个 $0 \le i < 2^{n-1}$,将 $x + 2i$ 加到 $a_{p_i}$ 上。

初始时,数组中的每个整数均为 $0$。HoshiYo 心中有一个理想数组 $b_0, b_1, \dots, b_{2^n-1}$。他想知道是否可以通过至多 $2^n$ 次魔法操作得到这个理想数组,即使得 $a_0 = b_0, a_1 = b_1, \dots, a_{2^n-1} = b_{2^n-1}$。

输入格式

第一行包含一个整数 $n$ ($1 \le n \le 11$),表示数组的长度为 $2^n$。 第二行包含 $2^n$ 个整数 $b_0, b_1, \dots, b_{2^n-1}$ ($0 \le b_i \le 10^5$),表示理想数组。

输出格式

如果无法通过至多 $2^n$ 次魔法操作得到理想数组,则输出 NO。 否则,第一行输出 YES,第二行输出一个整数 $k$ ($0 \le k \le 2^n$),表示使用魔法的次数。接下来输出 $k$ 行,每行包含 $2^{n-1} + 1$ 个整数 $x, p_0, p_1, \dots, p_{2^{n-1}-1}$,各数之间用空格分隔。你需要确保 $p_0, p_1, \dots, p_{2^{n-1}-1}$ 是 $0$ 到 $2^n - 1$ 之间互不相同的整数,且在操作过程中,$a_0, a_1, \dots, a_{2^n-1}$ 的值始终保持在 $[-10^{18}, 10^{18}]$ 范围内。 如果存在多种方案,输出任意一种即可。

样例

样例输入 1

2
1 14 5 14

样例输出 1

YES
4
0 1 0
2 1 2
12 1 3
-1 0 2

样例输入 2

2
11 45 1 4

样例输出 2

NO

说明

对于第一个样例,每次使用魔法后的结果如下:

  1. $\{0 + 2, 0 + 0, 0, 0\} = \{2, 0, 0, 0\}$
  2. $\{2, 0 + 2, 0 + 4, 0\} = \{2, 2, 4, 0\}$
  3. $\{2, 2 + 12, 4, 0 + 14\} = \{2, 14, 4, 14\}$
  4. $\{2 - 1, 14, 4 + 1, 14\} = \{1, 14, 5, 14\}$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.