#P6957. Fiora's Labyrinth
Fiora's Labyrinth
Fiora's Labyrinth
Fiora is a game designer working on the final level of her new game. The level is a labyrinth laid out on an infinite rectangular grid. The player starts at the square \((0,0)\) and must reach the destination square \((a,b)\).
The level is constructed using a basic L-shaped block. Each block consists of two perpendicular 1\times n rectangles that share a common square (the corner). Formally, if you choose the corner to be at \(C\), one arm of the block covers the set of squares \[ \{C + k\cdot(dx,0) : k = 0,1,\ldots,n-1\}\quad\text{and}\quad\{C + k\cdot(0,dy) : k = 0,1,\ldots,n-1\}\, , \] with \(dx,dy\in\{+1,-1\}\). Note that a block can be rotated, but when placed its arms extend only in one direction from the corner (they are not centered). Blocks may touch but cannot intersect. The player can walk from one square to another if they share a side and both are covered by some block(s).
Fiora wants to build a level that guarantees there is a path from \((0,0)\) to \((a,b)\) and uses the minimal number of blocks. It turns out that by carefully choosing the placement and size of the block, the answer depends solely on the coordinates \(a\) and \(b\):
- If \((a,b) = (0,0)\), no block is needed.
- If either \(a=0\) or \(b=0\), one block is sufficient (place the block with the corner at \((0,0)\)).
- If \(a\) and \(b\) have opposite signs (i.e. \(a\times b<0\)), one block is enough by placing the block so that \((0,0)\) lies on one arm and \((a,b)\) lies on the other.
- If \(a\) and \(b\) are both nonzero and have the same sign, one block cannot cover both \((0,0)\) and \((a,b)\) because the block’s arms extend in only one direction from its corner. In this case, at least 2 blocks are required.
Your task is to compute the minimum number of blocks needed.
inputFormat
The input consists of a single line with two space‐separated integers \(a\) and \(b\) \( (-10^9 \le a,b \le 10^9) \). \(a\) and \(b\) denote the coordinates of the destination square.
outputFormat
Output a single integer representing the minimum number of blocks required so that there is a path from \((0,0)\) to \((a,b)\).
sample
0 0
0