QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#18518. 真正的民谣蓝调

統計

你正在入侵红龙辛迪加的数据终端。终端的存档(记为 $S$)初始包含 $n$ 个加密信号频率,每个频率用一个长度为 $k$ 的二进制串表示。这些初始频率按照从终端内存中提取的精确顺序,从 $1$ 到 $n$ 编号。为了攻破核心,你必须合成新的频率并将其注入存档。每次合成操作会向 $S$ 末尾追加一个二进制串,自动分配下一个可用的整数索引。

你有两种操作:

  • 相位反转:选择一个已有的频率 $s$,追加它的精确按位取反(设 $s$ 是一个长度为 $k$ 的二进制串,$s = s_1 s_2 \dots s_k$,其中每位 $s_i \in \{0, 1\}$。$s$ 的按位取反通常记作 $\neg s$,定义为长度为 $k$ 的新二进制串,第 $i$ 位的值为 $1 - s_i$);
  • 信号三角测量:选择三个已有的频率 $u$、$v$ 和 $w$(不必互异),追加它们的按位多数,记作 $\operatorname{maj}(u,v,w)$。对于每个位位置 $i$,运算定义为: $$\operatorname{maj}(u,v,w)_i = \operatorname{maj}(u_i,v_i,w_i).$$ 对于单个位 $a$、$b$、$c$,$\operatorname{maj}(a,b,c)$ 的值为 $1$ 当且至少有两个为 $1$,否则为 $0$。

你的目标是判断是否能够合成一个特定的目标赏金代码 $t$(长度为 $k$)。如果可能,你需要给出一组操作序列(最多 $10^5$ 步),成功构造出它。

输入格式

终端输入的第一行包含两个整数 $n$ 和 $k$($1 \le n, k \le 200$),分别表示初始代码的数量和每个代码的长度。

接下来 $n$ 行,每行包含一个长度为 $k$ 的二进制串(由 01 组成),表示存档中已有的一个代码。

最后一行包含一个长度为 $k$ 的二进制串 $t$,表示你需要合成的目标赏金代码。

输出格式

如果无法合成目标代码 $t$,输出一行 NO

否则,输出 YES。在下一行输出一个整数 $m$($0 \le m \le 10^5$),表示你将使用的操作总数。然后输出 $m$ 行,按顺序描述你的操作:

  • 1 x:选择索引为 $x$ 的已有代码,执行相位反转(追加 $x$ 的按位取反);
  • 2 x y z:选择索引为 $x$、$y$、$z$ 的已有代码,执行信号三角测量(追加 $x$、$y$、$z$ 的按位多数)。

你使用的每个索引在操作时刻必须已经存在于存档中。完成所有 $m$ 次操作后,存档中至少有一个代码必须与目标 $t$ 完全一致。如果目标代码 $t$ 已经存在于初始存档中,你可以直接输出 $m = 0$。

如果存在多种正确的合成方式,你可以输出任意一个有效操作序列。

样例

样例输入 1

3 4
1000
0100
0010
1111

样例输出 1

YES
4
1 1
1 2
1 3
2 4 5 6

说明

  • 前三步操作追加了初始字符串的取反,得到 011110111101
  • 最后一步操作取这三个字符串的按位多数。
  • 在每个位置上,至少有两个字符串的位为 $1$,因此追加的字符串为 1111,这正是目标。

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.