QOJ.ac

QOJ

Time Limit: 4 s Memory Limit: 1024 MB Total points: 100

#6380. LaLa 与占卜魔法

Statistics

LaLa 擅长占卜魔法。

假设有 $M$ 个事件 $E_0, \dots, E_{M-1}$ 是 LaLa 感兴趣的预测对象。每个事件都有两种可能的结果:灾难(catastrophe)或救赎(salvation)。

通过一次占卜魔法,LaLa 可以获得以下四种形式之一的知识:

  1. $\text{Knowledge}(i, j, 1)$:$E_i$ 是灾难,或者 $E_j$ 是灾难(可能两者都是)。
  2. $\text{Knowledge}(i, j, 2)$:$E_i$ 是救赎,或者 $E_j$ 是灾难(可能两者都是)。
  3. $\text{Knowledge}(i, j, 3)$:$E_i$ 是灾难,或者 $E_j$ 是救赎(可能两者都是)。
  4. $\text{Knowledge}(i, j, 4)$:$E_i$ 是救赎,或者 $E_j$ 是救赎(可能两者都是)。

LaLa 施展了若干次(可能为 0 次)魔法,并写下了所有与她所获知识相符的 $M$ 元组事件结果:这被称为预测结果。随后,LaLa 睡着了。

当 LaLa 醒来时,她发现她的宠物 Leo 弄乱了她所有的魔法预测。虽然 LaLa 能够找到她预测的结果,但她不确定这些数据是否也被 Leo 弄乱了。

请编写一个程序,判断是否存在一组 LaLa 的魔法预测,使得其预测结果与 LaLa 手中的结果相匹配;如果存在,请找出一组可能的预测。

输入格式

输入格式如下:

$N \ M$ $S_0$ $S_1$ $\vdots$ $S_{N-1}$

其中 $N$ 是结果中的结果数量,$M$ 是事件数量,$S_i$ 是长度为 $M$ 的二进制字符串,若其第 $j$ 个字符为 '1',则表示第 $i$ 个结果预测第 $j$ 个事件为救赎。

输入满足以下约束:

  • $N$ 和 $M$ 为整数。
  • $1 \le N, M \le 2\,000$
  • 对于所有 $0 \le i < j < N$,满足 $S_i \neq S_j$。

输出格式

如果不存在这样的预测,输出单个整数 $-1$。

否则,输出格式如下:

$K$ $I_0 \ J_0 \ t_0$ $I_1 \ J_1 \ t_1$ $\vdots$ $I_{K-1} \ J_{K-1} \ t_{K-1}$

其中 $K$ 是可能的预测集合 $S$ 的大小,对于每个 $0 \le i < K$,$S$ 包含预测 $\text{Knowledge}(I_i, J_i, t_i)$。

输出应满足以下约束:

  • $0 \le K \le 2 \cdot M^2$

可以证明,如果存在这样一组预测,则一定存在满足该约束的预测。

样例

样例输入 1

2 1
1
0

样例输出 1

0

样例输入 2

3 3
101
011
111

样例输出 2

6
0 2 3
0 1 4
0 2 4
1 2 3
1 2 4
2 2 4

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.