Official

A - 色紙の正方形 / Shikishi Squares Editorial by admin Editorial for printing

gpt-6-astra-medium

Overview

Find the maximum number of squares with sides parallel to the rectangle that can be cut out from a rectangular sheet of colored paper. We can calculate the number of squares that can fit vertically and horizontally, and take their product.

Analysis

Since the vertical length is \(A\) cm and the side length of each square is \(C\) cm, the number of squares that can be placed vertically is

\(\left\lfloor \frac{A}{C} \right\rfloor\).

Here, \(\lfloor x \rfloor\) denotes the floor function, representing the integer obtained by truncating the fractional part of \(x\).

Similarly, the number of squares that can be placed horizontally is

\(\left\lfloor \frac{B}{C} \right\rfloor\).

By arranging the squares tightly in a grid pattern, we can cut out at most

\(\boxed{\left\lfloor \frac{A}{C} \right\rfloor \times \left\lfloor \frac{B}{C} \right\rfloor}\)

squares.

For example, when \(A=7,\ B=10,\ C=3\), we can fit \(2\) squares vertically and \(3\) squares horizontally, so the answer is \(2 \times 3 = 6\) squares. The remaining margins vertically and horizontally have a width of less than \(C\) cm, so no additional squares can be cut out from them.

Why Calculating by Area Alone is Incorrect

Dividing the area of the paper by the area of a square, \(\left\lfloor \frac{AB}{C^2} \right\rfloor\), does not necessarily equal the number of squares that can be cut out. This is because even if the total area is sufficient, the squares might not fit due to insufficient vertical or horizontal dimensions.

For example, when \(A=B=5,\ C=3\), calculating from the area gives \(\lfloor 25/9 \rfloor=2\) squares, but in reality, only \(1\) square can be placed both vertically and horizontally, making the answer \(1\) square.

There is no need to try each arrangement; we can simply find the answer by performing integer division on the vertical and horizontal lengths separately.

Algorithm

  1. Read \(A,\ B,\ C\).
  2. Compute the number of squares in the vertical direction using A // C.
  3. Compute the number of squares in the horizontal direction using B // C.
  4. Output their product.

Complexity

  • Time complexity: \(O(1)\)
  • Space complexity: \(O(1)\)

Implementation Notes

  • In Python, // denotes integer division. Since all values are positive integers here, it yields the quotient with the fractional part truncated.
  • It is important to divide the vertical and horizontal lengths separately before multiplying, rather than computing A * B // (C * C).
  • If \(A<C\) or \(B<C\), the corresponding quotient becomes \(0\). Therefore, the correct answer of \(0\) is output without needing any special conditional branching.
A, B, C = map(int, input().split())
print((A // C) * (B // C))

Source Code

A, B, C = map(int, input().split())
print((A // C) * (B // C))

This editorial was generated by gpt-6-astra-medium.

posted:
last update: