#abc359c. C - Tile Distance 2
C - Tile Distance 2
Score : points
问题陈述
坐标平面上覆盖着 的瓷砖。这些瓷砖按照以下规则铺设:
- 对于整数对 ,正方形 $A _ {i,j}=\lbrace(x,y)\mid i\leq x\leq i+1 \wedge j\leq y\leq j+1\rbrace$ 包含在一个瓷砖内。
- 当 为偶数时, 和 包含在同一个瓷砖内。
瓷砖包括它们的边界,并且没有两个不同的瓷砖共享一个正面积。
在原点附近,瓷砖的铺设方式如下:
高桥从坐标平面上的点 开始。
他可以重复以下移动任意次数:
- 选择一个方向(上、下、左或右)和一个正整数 。在那个方向上移动 个单位。
每次他进入一个瓷砖,他需要支付 1 元的通行费。
找出他到达点 必须支付的最小通行费。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
The coordinate plane is covered with tiles. The tiles are laid out according to the following rules:
- For an integer pair , the square $A _ {i,j}=\lbrace(x,y)\mid i\leq x\leq i+1\wedge j\leq y\leq j+1\rbrace$ is contained in one tile.
- When is even, and are contained in the same tile.
Tiles include their boundaries, and no two different tiles share a positive area.
Near the origin, the tiles are laid out as follows:
Takahashi starts at the point on the coordinate plane.
He can repeat the following move as many times as he likes:
- Choose a direction (up, down, left, or right) and a positive integer . Move units in that direction.
Each time he enters a tile, he pays a toll of .
Find the minimum toll he must pay to reach the point .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the minimum toll Takahashi must pay.
Sample Input 1
5 0
2 5
Sample Output 1
5
For example, Takahashi can pay a toll of by moving as follows:
- Move left by . Pay a toll of .
- Move up by . Pay a toll of .
- Move left by . Pay a toll of .
- Move up by . Pay a toll of .
- Move left by . Pay a toll of .
- Move up by . Pay a toll of .
It is impossible to reduce the toll to or less, so print 5
.
Sample Input 2
3 1
4 1
Sample Output 2
0
There are cases where no toll needs to be paid.
Sample Input 3
2552608206527595 5411232866732612
771856005518028 7206210729152763
Sample Output 3
1794977862420151
Note that the value to be output may exceed the range of a -bit integer.