QOJ.ac

QOJ

حد الوقت: 2 s حد الذاكرة: 512 MB مجموع النقاط: 100

#8564. 三个向量

الإحصائيات

给定三个长度为 $n$ 的不同二进制向量。请找到一个满足以下条件的 2-CNF 公式:

  • 该公式在这三个向量上均为真;
  • 使该公式为真的向量数量尽可能少;
  • 该公式的长度不能过长。

回想一下,2-CNF 公式是 $n$ 个布尔变量 $v_1, \dots, v_n$ 的命题公式,形式如下: $$C_1 \land C_2 \land \dots \land C_m$$ 其中每个子句 $C_i$ 表示为两个文字的析取 $\pm x_{i1} \lor \pm x_{i2}$(文字指任何变量或其否定)。这里 $x_{ij} \in {v_1, \dots, v_n}$ 是变量之一,而 $\neg x_{ij}$ 是其否定:真变为假,假变为真。如果 $f(v_1, v_2, \dots, v_n) = 1$,则称公式 $f$ 在二进制向量 $v$ 上为真。

如果有多个合法的公式,你可以输出其中任意一个。

输入格式

第一行包含一个整数 $n$,表示三个向量的长度($2 \le n \le 10^5$)。接下来的三行,每行包含一个长度为 $n$ 的二进制字符串,表示第 $i$ 个二进制向量。

任意两个向量均不相同。

输出格式

第一行输出一个整数 $m$($0 \le m \le 2 \cdot 10^5$)。然后输出 $m$ 行,第 $i$ 行包含两个整数 $a_i$ 和 $b_i$($1 \le |a_i|, |b_i| \le n$),表示第 $i$ 个子句是两个文字的析取:如果 $a_i > 0$ 则第一个文字为 $v_{a_i}$,否则为 $\neg v_{|a_i|}$;同理,如果 $b_i > 0$ 则第二个文字为 $v_{b_i}$,否则为 $\neg v_{|b_i|}$。如果你的公式为空(即 $m = 0$),则认为它对所有可能的长度为 $n$ 的输入向量均为真。

请注意,如果你使用的子句数量过多,你的答案将被视为错误。

样例

样例 1

5
00101
10011
11011
6
-1 -3
3 1
-1 4
-4 1
5 5
-2 1

样例 2

3
100
010
001
3
-2 -1
-3 -1
-3 -2

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.