QOJ.ac

QOJ

时间限制: 1 s 内存限制: 512 MB 总分: 100

#4541. 黑魔法

统计

HoshiYo 正在学习一种有 $n$ 个方块的“黑魔法”。每个方块的左侧和右侧都被涂成了黑色或白色。HoshiYo 将这些方块按某种顺序排成一行,且不能旋转它们,然后释放“黑魔法”。接下来会发生以下情况:

  • 对于任意两个相邻的方块,如果左侧方块的右侧和右侧方块的左侧都被涂成了黑色,那么这两个侧面会粘在一起,使这两个方块合并为一个。

HoshiYo 想知道在释放“黑魔法”后,他能得到的最少和最多的方块数量。

输入格式

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

每个测试用例包含四个整数 $E, L, R, B$ ($0 \le E, L, R, B \le 10^5, E + L + R + B \ge 1$),分别表示各类方块的数量:

  • $E$:两侧均为白色的方块数量。
  • $L$:左侧为黑色、右侧为白色的方块数量。
  • $R$:右侧为黑色、左侧为白色的方块数量。
  • $B$:两侧均为黑色的方块数量。

保证所有测试用例的 $E + L + R + B$ 之和不超过 $10^6$。

输出格式

对于每个测试用例,输出一行两个整数,分别表示 HoshiYo 能得到的最少和最多的方块数量。

样例

样例输入 1

3
1 1 1 1
1 2 3 4
3 4 5 6

样例输出 1

2 4
4 8
8 16

说明

用 $(x, y)$ 表示一个方块,其中 $x$ 表示左侧的颜色,$y$ 表示右侧的颜色。我们用 $0$ 表示白色,$1$ 表示黑色。

对于样例中的第一个测试用例,以下是一种得到最少方块数量的方案:

$(0, 0) \quad (0, 1) \quad (1, 1) \quad (1, 0)$

如上所示,最后三个方块将合并为一个。

以下是一种得到最多方块数量的方案:

$(0, 0) \quad (1, 0) \quad (1, 1) \quad (0, 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.