QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#16932. 钥匙与锁的布尔逻辑

Statistics

Karen 和她的朋友们在 Karen 的车库里组建了一个乐团。对于应该允许乐团的哪些子集进入车库,她有着复杂的想法。她设计了一个布尔公式 $F$,其中每个变量表示某个乐团成员是否到场。她希望当且仅当 $F$ 为真(true)时,来的一组人才能进入车库。

你需要设计一个由导线和锁组成的系统来满足公式 $F$。每个乐团成员都会得到一把钥匙,可以打开所有用他们名字字母表示的锁。

例如,假设 $F = a \lor (b \land c)$,且乐团成员 $a$ 和 $b$ 到场。那么他们应该能够用他们的钥匙进入车库,因为 $\text{true} \lor (\text{true} \land \text{false}) = \text{true}$。

乐团成员不需要用他们的钥匙去打开所有能打开的锁。例如,假设 $F = a \oplus b$。那么仅有成员 $a$ 到场时应该能够进入车库,因为 $\text{true} \oplus \text{false} = \text{true}$。但如果 $a$ 和 $b$ 都来到了车库,他们可以不使用 $b$ 的钥匙,而仅用 $a$ 的钥匙来打开车库。然而,$\text{true} \oplus \text{true} = \text{false}$,因此这个公式 $F$ 是无法实现的。

该系统必须是一个大小最多为 $50 \times 50$ 的矩形网格,其中包含水平导线 '-'、垂直导线 '|'、导线连接点 '+' 以及锁。网格的左上角和右上角单元格必须包含导线连接点,这些连接点将连接到车库的门上。只要这两个连接点之间存在一条通过导线和未打开的锁(locked locks)相连的路径,车库门就会保持关闭。

你的任务是设计一个与给定的布尔公式 $F$ 相对应的系统,或者指出不存在这样的系统。

输入格式

输入包含一个非空的布尔公式 $F$。

公式中可以包含字母 a, ..., h(表示乐团成员是否到场)、运算符 "and"、"or"、"not" 以及括号。公式的长度不超过 2020。运算符 "not" 具有最高优先级,"and" 的优先级高于 "or"。每个 "and" 和 "or" 的前后各有一个空格,每个 "not" 后面有一个空格。除此之外没有其他空格。

输出格式

如果无法设计出满足要求的系统,输出一行 "IMPOSSIBLE"

否则,输出一个字符矩形网格,表示与公式 $F$ 相对应的系统。该系统只能包含空格、'-''|''+' 以及输入中提到的乐团成员对应的字母。

网格的左上角和右上角单元格必须是导线连接点 '+'。网格的宽度应在 $2$ 到 $50$ 之间(含),高度应在 $1$ 到 $50$ 之间(含)。

字符 '-' 当且仅当连接其左侧 and 右侧的某些元素,且其上方和下方为空格时,才能用于表示导线。类似地,字符 '|' 当且仅当连接其下方和上方的某些元素,且其左侧和右侧为空格时,才能用于表示导线。

样例

输入格式 1

a or (b and c)

输出格式 1

+-+ +b-+
| | |  |
+-a-+-c+

输入格式 2

(a or f) and ((a and g) or (a and h))

输出格式 2

+a-f+
|   |
+g+h+
a | a
+-+-+

输入格式 3

a and not b or not a and b

输出格式 3

IMPOSSIBLE

输入格式 4

b or not b

输出格式 4

++

输入格式 5

d and not d

输出格式 5

+ +---+ +---+--+---+
| |   | |   |  |   |
+--+  +---+ |
|  |  |   | |
+  +------+ +---+

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.