公式

A - 色紙の正方形 / Shikishi Squares 解説 by admin

swe-2-high

We can place \(\lfloor A/C \rfloor\) squares vertically and \(\lfloor B/C \rfloor\) horizontally in a grid, so the answer is at least their product. To see we cannot do better, assign each cut square’s lower-left corner \((x, y)\), where \(0 \le x \le B - C\) and \(0 \le y \le A - C\), to the bin \((\lfloor x/C \rfloor, \lfloor y/C \rfloor)\). If two squares land in the same bin, their corners differ by less than \(C\) in both coordinates, and since the sides are parallel they must overlap — impossible. Hence the number of squares is at most the number of bins, \(\lfloor A/C \rfloor \times \lfloor B/C \rfloor\), which the grid attains. Both time and space are \(O(1)\).