CF1715A.Crossmarket
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Stanley and Megan decided to shop in the "Crossmarket" grocery store, which can be represented as a matrix with n rows and m columns.
Stanley and Megan can move to an adjacent cell using 1 unit of power. Two cells are considered adjacent if they share an edge. To speed up the shopping process, Megan brought her portals with her, and she leaves one in each cell she visits (if there is no portal yet). If a person (Stanley or Megan) is in a cell with a portal, that person can use 1 unit of power to teleport to any other cell with a portal, including Megan's starting cell.
They decided to split up: Stanley will go from the upper-left cell (cell with coordinates (1,1)) to the lower-right cell (cell with coordinates (n,m)), whilst Megan needs to get from the lower-left cell (cell with coordinates (n,1)) to the upper-right cell (cell with coordinates (1,m)).
What is the minimum total energy needed for them both to do that?
Note that they can choose the time they move. Time does not affect energy.
斯坦利和梅根决定在“十字市场”杂货店购物,该商店可表示为一个 n 行 m 列的矩阵。
斯坦利和梅根每次移动到一个相邻格子需消耗 1 单位能量。若两个格子共享一条边,则称它们相邻。为加快购物过程,梅根随身携带了传送门,并在她所经过的每个格子(若该格子尚无传送门)留下一个传送门。若某人(斯坦利或梅根)位于一个已有传送门的格子中,则此人可消耗 1 单位能量,瞬移到任意一个已有传送门的格子(包括梅根的起始格子)。
他们决定分头行动:斯坦利需从左上角格子(坐标为 (1,1))前往右下角格子(坐标为 (n,m)),而梅根需从左下角格子(坐标为 (n,1))前往右上角格子(坐标为 (1,m))。
他们共同完成上述目标所需的最小总能量是多少?
注意:他们可以自由选择各自的移动时刻,时间本身不影响能量消耗。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤1000). Description of the test cases follows.
The only line in the test case contains two integers n and m (1≤n,m≤105).
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤1000)。随后是测试用例的描述。
每个测试用例仅有一行,包含两个整数 n 和 m(1≤n,m≤105)。
输出格式
For each test case print a single integer on a new line – the answer.
对于每个测试用例,在新的一行上输出一个整数——即答案。
输入输出样例
输入#1
7 7 5 5 7 1 1 100000 100000 57 228 1 5 5 1
输出#1
15 15 0 299998 340 5 5
说明/提示

In the first test case they can stick to the following plan:
- Megan (red circle) moves to the cell (7,3). Then she goes to the cell (1,3), and Stanley (blue circle) does the same.
- Stanley uses the portal in that cell (cells with portals are grey) to get to the cell (7,3). Then he moves to his destination — cell (7,5).
- Megan also finishes her route and goes to the cell (1,5).
The total energy spent is (2+6)+(2+1+2)+(2)=15, which is our final answer.

在第一个测试用例中,他们可以遵循以下计划:
- 梅根(红色圆圈)移动到格子 (7,3),然后前往格子 (1,3);斯坦利(蓝色圆圈)也执行相同的移动。
- 斯坦利利用该格子中的传送门(带传送门的格子为灰色)到达格子 (7,3),随后再移动至其目的地——格子 (7,5)。
- 梅根也完成自己的路径,前往格子 (1,5)。
总共消耗的能量为 (2+6)+(2+1+2)+(2)=15,即为本题最终答案。
输入解题思路,AI测评打分。不知道怎么写?