QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100 قابلة للهجوم ✓

#9750. 拼图

الإحصائيات

2 × 2 和 3 × 3 矩形示例,A、B、C、D 代表四种基本块

小 Y 想要玩一种由四种基本块组成的拼图,如图所示。小 Y 拥有这四种类型的块各 $A, B, C, D$ 个。现在他想尽可能多地使用这些块来拼成一个矩形(矩形或正方形)。问题是,他最多能使用多少个块?

拼成的矩形必须满足以下条件:

  1. 任意两个相邻的基本块必须形成凹凸咬合结构;
  2. 拼成的矩形的四条边不能有任何凸起或凹陷;
  3. 与普通拼图游戏不同,此游戏中的块没有图案,且相同类型的块被视为完全相同。

输入格式

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

对于每个测试用例,每一行包含四个整数 $A, B, C, D$ ($0 \le A, B, C, D \le 10^3$),分别表示四种基本块的数量。

输出格式

输出 $T$ 行,每行包含一个整数,表示能够拼成矩形所使用的块的最大数量。如果无法拼成矩形,请输出 0。

样例

输入 1

2
4 0 0 0
4 4 4 4

输出 1

4
16

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.