A12002 | Diagonal Walking v.2
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Mikhail walks on a Cartesian plane. He starts at the point $(0, 0)$ , and in one move he can go to any of eight adjacent points. For example, if Mikhail is currently at the point $(0, 0)$ , he can go to any of the following points in one move:
- $(1, 0)$ ;
- $(1, 1)$ ;
- $(0, 1)$ ;
- $(-1, 1)$ ;
- $(-1, 0)$ ;
- $(-1, -1)$ ;
- $(0, -1)$ ;
- $(1, -1)$ .
If Mikhail goes from the point $(x1, y1)$ to the point $(x2, y2)$ in one move, and $x1 \ne x2$ and $y1 \ne y2$ , then such a move is called a diagonal move.
Mikhail has $q$ queries. For the $i$ -th query Mikhail's target is to go to the point $(n_i, m_i)$ from the point $(0, 0)$ in exactly $k_i$ moves. Among all possible movements he want to choose one with the maximum number of diagonal moves. Your task is to find the maximum number of diagonal moves or find that it is impossible to go from the point $(0, 0)$ to the point $(n_i, m_i)$ in $k_i$ moves.
Note that Mikhail can visit any point any number of times (even the destination point!).
- $(1, 0)$ ;
- $(1, 1)$ ;
- $(0, 1)$ ;
- $(-1, 1)$ ;
- $(-1, 0)$ ;
- $(-1, -1)$ ;
- $(0, -1)$ ;
- $(1, -1)$ .
If Mikhail goes from the point $(x1, y1)$ to the point $(x2, y2)$ in one move, and $x1 \ne x2$ and $y1 \ne y2$ , then such a move is called a diagonal move.
Mikhail has $q$ queries. For the $i$ -th query Mikhail's target is to go to the point $(n_i, m_i)$ from the point $(0, 0)$ in exactly $k_i$ moves. Among all possible movements he want to choose one with the maximum number of diagonal moves. Your task is to find the maximum number of diagonal moves or find that it is impossible to go from the point $(0, 0)$ to the point $(n_i, m_i)$ in $k_i$ moves.
Note that Mikhail can visit any point any number of times (even the destination point!).
输入格式
The first line of the input contains one integer $q$ ( $1 \le q \le 10^4$ ) — the number of queries.
Then $q$ lines follow. The $i$ -th of these $q$ lines contains three integers $n_i$ , $m_i$ and $k_i$ ( $1 \le n_i, m_i, k_i \le 10^{18}$ ) — $x$ -coordinate of the destination point of the query, $y$ -coordinate of the destination point of the query and the number of moves in the query, correspondingly.
Then $q$ lines follow. The $i$ -th of these $q$ lines contains three integers $n_i$ , $m_i$ and $k_i$ ( $1 \le n_i, m_i, k_i \le 10^{18}$ ) — $x$ -coordinate of the destination point of the query, $y$ -coordinate of the destination point of the query and the number of moves in the query, correspondingly.
输出格式
Print $q$ integers. The $i$ -th integer should be equal to -1 if Mikhail cannot go from the point $(0, 0)$ to the point $(n_i, m_i)$ in exactly $k_i$ moves described above. Otherwise the $i$ -th integer should be equal to the the maximum number of diagonal moves among all possible movements.
输入输出样例
输入 #1
3 2 2 3 4 3 7 10 1 9
输出 #1
1 6 -1
One of the possible answers to the first test case: $(0, 0) \to (1, 0) \to (1, 1) \to (2, 2)$ .
One of the possible answers to the second test case: $(0, 0) \to (0, 1) \to (1, 2) \to (0, 3) \to (1, 4) \to (2, 3) \to (3, 2) \to (4, 3)$ .
In the third test case Mikhail cannot reach the point $(10, 1)$ in 9 moves.
One of the possible answers to the second test case: $(0, 0) \to (0, 1) \to (1, 2) \to (0, 3) \to (1, 4) \to (2, 3) \to (3, 2) \to (4, 3)$ .
In the third test case Mikhail cannot reach the point $(10, 1)$ in 9 moves.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted