QOJ.ac

QOJ

時間限制: 3 s 記憶體限制: 512 MB 總分: 100

#10447. 稳妥的赌注

统计

Safe Ltd. 是一家制造高质量保险柜的公司。其最新发明是一种光学闭锁机制,它利用激光束穿过带有若干镜子的矩形网格。

光束被检测到,保险柜开启

光束未被检测到,触发警报

当激光激活时,光束从网格左侧水平进入第一行。光束会被它碰到的每一面镜子反射。每面镜子都有 45 度的对角线方向,即 /\。如果光束从网格底行水平向右射出,则会被检测到,保险柜开启(见上图左侧)。否则,保险柜保持关闭并触发警报。

每个保险柜都缺少一面镜子,这导致激光束无法成功穿过网格(见上图右侧)。保险柜有一个机制,允许用户在任何空的网格单元中放入一面镜子。合法用户知道缺失镜子的正确位置和方向(如上图第 4 行第 3 列的 /),从而可以打开保险柜。如果没有这些知识,用户就必须进行猜测,这对于大型网格的保险柜来说可能很困难。

你的任务是确定特定的保险柜是否确实是安全的。一个安全的保险柜在不插入镜子时不会立即打开,并且至少存在一个有效的缺失镜子位置和方向。实际上可能存在多个这样的位置和方向。

输入格式

每个测试用例描述一个保险柜,并以包含四个整数 $r, c, m, n$ 的行开始($1 \le r, c \le 1\,000\,000$ 且 $0 \le m, n \le 200\,000$)。该机制的网格有 $r$ 行和 $c$ 列。接下来的 $m$ 行,每行包含两个整数 $r_i$ 和 $c_i$($1 \le r_i \le r$ 且 $1 \le c_i \le c$),指定在第 $r_i$ 行第 $c_i$ 列有一面 / 镜子。随后的 $n$ 行以同样的方式指定 \ 镜子的位置。这 $m+n$ 个镜子位置互不相同。

输出格式

对于每个测试用例,显示其用例编号,后跟:

  • 如果保险柜在不插入镜子的情况下就能打开,输出 0
  • 如果保险柜在不插入镜子时无法打开,且存在恰好 $k$ 个位置,通过在这些位置插入镜子可以打开保险柜,则输出 $k\ r\ c$,其中 $(r, c)$ 是这些位置中字典序最小的行、列坐标。在同一位置插入 /\ 镜子均能打开保险柜的情况仅计作一次。
  • 如果无论是否插入镜子都无法打开保险柜,输出 impossible

样例

输入 1

5 6 1 4
2 3
1 2
2 5
4 2
5 5
100 100 0 2
1 77
100 77
100 100 0 0

输出 1

Case 1: 2 4 3
Case 2: 0
Case 3: impossible

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.