QOJ.ac

QOJ

时间限制: 3.0 s 内存限制: 1024 MB 总分: 100

#9969. 幼儿园广场

统计

幼儿园的孩子们正在学习自然数。老师在黑板上写下了从 $1$ 到 $h \cdot w$ 的连续整数,排列成 $h$ 行 $w$ 列($h, w \ge 2$)。因此,第一行包含从 $1$ 到 $w$ 的数字(从左到右),第二行包含从 $w + 1$ 到 $2 \cdot w$ 的数字,以此类推。课后,老师擦掉了除了一个包含四个相邻数字的 $2 \times 2$ 连续方块之外的所有数字。

下图展示了 $h = 3, w = 4$ 时的黑板,以及一个剩余 $2 \times 2$ 方块的示例:

其中一名幼儿园学生 Kamilek 上课时没怎么注意听讲,现在他想知道老师当时使用的 $h$ 和 $w$ 是多少。请找出任意一组可能的 $h$ 和 $w$,如果给定的方块不可能由上述方式得到,则输出 $-1$。这种情况会重复 $t$ 天,即给定 $t$ 组独立的测试用例。

输入格式

第一行包含一个整数 $t$ ($1 \le t \le 10$),表示测试用例的数量。

接下来的 $2 \cdot t$ 行描述了这些测试用例。每个测试用例包含两行,每行有两个范围在 $[1, 50\,000]$ 内的整数,表示剩余的 $2 \times 2$ 方块。

输出格式

输出 $t$ 行,第 $i$ 行包含第 $i$ 个测试用例的解:

  • 如果给定的方块可能由上述方式得到,输出两个由空格分隔的整数——黑板的任意一组可能维度 $h, w$ ($2 \le h, w \le 100\,000$)。可以证明,如果存在任何有效的 $(h, w)$,则一定存在满足这些不等式的解。如果存在多组解,输出其中任意一组即可。
  • 如果该方块不可能由上述方式得到,输出单个数字 $-1$。

样例

输入 1

4
6 7
10 11
2 3
4 5
8 5
5 13
1 2
5 6

输出 1

3 4
-1
-1
3 4

说明

在第一个测试用例中,我们得到的方块为 $[[6, 7], [10, 11]]$。上图展示了多种正确解法中的一种:$h = 3, w = 4$。这也是第四个测试用例 $[[1, 2], [5, 6]]$ 的正确解法之一。

在第二个测试用例中,数字 $[[2, 3], [4, 5]]$ 虽然可能最初由老师写下,但它们永远无法构成一个 $2 \times 2$ 的方块。因此答案为 $-1$。

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.