DeepInfra Round 1(Codeforces Round 1126,Div. 1 + Div. 2)
A
机器人的奇数移动
Robot Odd Moves
Codeforces
800
原题
←B →

机器人的奇数移动AI (CI翻译)

You are given a point $(a, b)$ of the integer grid.

给定整数网格上的一个点 $(a, b)$。AI (CI翻译)

A robot is standing at the point $(0, 0)$. The robot may perform the following two-step operation any number of times (possibly zero), where $(x, y)$ denotes the point the robot is standing at:

一个机器人位于点 $(0, 0)$。机器人可以执行任意次(也可以是零次)以下由两个步骤组成的操作,其中 $(x, y)$ 表示机器人当前所在的点:AI (CI翻译)

  1. Move one unit up or one unit down: $(x, y) \rightarrow (x, y + 1)$ or $(x, y) \rightarrow (x, y - 1)$.
  2. Then move one unit to the right: $(x, y) \rightarrow (x + 1, y)$.
  1. 向上或向下移动一个单位:$(x, y) \rightarrow (x, y + 1)$ 或 $(x, y) \rightarrow (x, y - 1)$。
  2. 然后向右移动一个单位:$(x, y) \rightarrow (x + 1, y)$。
AI (CI翻译)

The robot visits a point if at some moment it is standing at this point: before the first operation, between the two moves of an operation, or after an operation.

如果机器人在某一时刻位于某个点,就称机器人访问了该点。这个时刻可以是第一次操作之前、一次操作的两步移动之间,或一次操作之后。AI (CI翻译)

Find the minimum number of operations after which the robot has visited $(a, b)$, or determine that it is impossible.

求机器人访问过 $(a, b)$ 所需的最少操作次数,或判断这是不可能的。AI (CI翻译)

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.

每个输入包含多组测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 100$)。接下来是各组测试用例的描述。AI (CI翻译)

The only line of each test case contains two integers $a$ and $b$ ($0 \le a, b \le 1000$) — the coordinates of the given point.

每组测试用例仅包含一行,其中有两个整数 $a$ 和 $b$($0 \le a, b \le 1000$)——给定点的坐标。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, output a single integer — the minimum number of operations after which the robot has visited $(a, b)$, or $-1$ if it is impossible.

对于每组测试用例,输出一个整数——机器人访问过 $(a, b)$ 所需的最少操作次数;如果不可能,则输出 $-1$。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first example, the robot is standing at $(0, 0)$ before the first operation, so it has already visited $(0, 0)$ after $0$ operations.

在第一个样例中,机器人在第一次操作之前就位于 $(0, 0)$,因此执行 $0$ 次操作后,它就已经访问过 $(0, 0)$。AI (CI翻译)

In the second example, the robot moves up to $(0, 1)$ and then right to $(1, 1)$ during its first operation. Thus, it visits $(0, 1)$ after $1$ operation.

在第二个样例中,机器人在第一次操作中先向上移动到 $(0, 1)$,再向右移动到 $(1, 1)$。因此,执行 $1$ 次操作后,它就访问过 $(0, 1)$。AI (CI翻译)

In the third example, it can be proven that the robot cannot visit $(0, 2)$.

在第三个样例中,可以证明机器人无法访问 $(0, 2)$。AI (CI翻译)

In the fourth example, the robot can first move up and right, and then down and right. During the second operation, it visits $(1, 0)$. It cannot visit this point during the first operation, so the answer is $2$.

在第四个样例中,机器人可以先向上、向右移动,再向下、向右移动。在第二次操作过程中,它会访问 $(1, 0)$。它无法在第一次操作过程中访问这个点,因此答案为 $2$。AI (CI翻译)

样例

Input #1
9
0 0
0 1
0 2
1 0
2 1
2 3
5 6
1000 999
1000 1000
Output #1
0
1
-1
2
3
3
6
1001
1000
InputCopy OutputCopy
题目信息
题号
2271A
时间限制
1 s
内存限制
256 MB
标签
构造
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。