#P10898. Puzzle Game: Maximum Square Tiling
Puzzle Game: Maximum Square Tiling
Puzzle Game: Maximum Square Tiling
In this problem, Little Blue has two types of square blocks: 2×2 blocks and 1×1 blocks. He possesses A = 7385137888721 pieces of 2×2 blocks and B = 10470245 pieces of 1×1 blocks. He wants to select some of these blocks to completely tile a square with side length n without gaps or overlaps.
The tiling is performed by placing whole blocks such that the total area covered is exactly n2. A 2×2 block covers an area of 4, while a 1×1 block covers an area of 1. Thus, if we use x pieces of the 2×2 blocks and y pieces of the 1×1 blocks, we must have:
with the constraints 0 ≤ x ≤ A and 0 ≤ y ≤ B.
For example:
- Using 3 pieces of 2×2 blocks and 4 pieces of 1×1 blocks, one can form a 4×4 square since \(4\times3+4=16\).
- Using 9 pieces of 2×2 blocks (and no 1×1 blocks), one can form a 6×6 square since \(4\times9=36\).
Your task is to find the maximum possible side length n of a square that can be tiled with some selection of these blocks.
Hint: Think about how to use the 2×2 blocks to cover as much area as possible (especially when the required area is a multiple of 4) while using 1×1 blocks to fill in gaps for squares whose area is not divisible by 4.
inputFormat
The input consists of two space‐separated integers A
and B
representing the number of available 2×2 blocks and 1×1 blocks respectively.
For this problem, the test input values will be exactly:
7385137888721 10470245
outputFormat
Output a single integer, the maximum side length n of the square that Little Blue can tile with the selected blocks.
For example, if the input is:
3 4
the output should be:
4
sample
3 4
4