A - 色紙の正方形 / Shikishi Squares Editorial by admin Editorial for printing
gpt-6-astra-mediumOverview
We find how many squares of side length \(C\) cm can be arranged vertically and horizontally on a rectangular sheet of colored paper, and output their product.
Analysis
Since the height (vertical length) is \(A\) cm, the number of squares that can be placed vertically is
\(\left\lfloor \dfrac{A}{C} \right\rfloor\).
Similarly, the number of squares that can be placed horizontally is
\(\left\lfloor \dfrac{B}{C} \right\rfloor\).
Here, \(\lfloor x \rfloor\) represents the value of \(x\) rounded down (the floor of \(x\)).
Therefore, by arranging them tightly without gaps vertically and horizontally, we can cut out
\(\left\lfloor \dfrac{A}{C} \right\rfloor \times \left\lfloor \dfrac{B}{C} \right\rfloor\)
squares.
Even by shifting their positions, we cannot cut out any more squares. If we classify the top-left corner of each square into intervals of \(C\) cm vertically and horizontally, the number of possible bins is equal to the product above. If two squares have their top-left corners in the same bin, the differences in both their vertical and horizontal positions will be strictly less than \(C\) cm, meaning the two squares would overlap.
Do Not Calculate Based on Area Alone
Dividing the area of the paper by the area of the square, \(\left\lfloor AB/C^2 \right\rfloor\), is not necessarily the answer. This is because even if the remaining total area is sufficient, a square cannot be cut out if the remaining width or height is insufficient.
For example, when \(A=5,\ B=5,\ C=3\), calculating by area alone would give \(\left\lfloor 25/9 \right\rfloor=2\) squares, but in reality, only \(1\) square fits both vertically and horizontally, so the answer is \(1\).
There is no need to search for arrangements; the answer can be obtained simply by integer division along the vertical and horizontal dimensions.
Algorithm
- Read \(A,B,C\) as input.
- Find the number of squares that fit vertically by \(A \mathbin{//} C\).
- Find the number of squares that fit horizontally by \(B \mathbin{//} C\).
- Output the product of the two counts.
For example, if \(A=8,\ B=11,\ C=3\), we can fit \(2\) squares vertically and \(3\) squares horizontally, so the answer is \(2 \times 3=6\).
Complexity
- Time complexity: \(O(1)\)
- Space complexity: \(O(1)\)
Implementation Notes
- Using
//in Python performs integer division. Since all values here are positive integers, it gives the quotient with the fractional part rounded down. - Divide along the vertical and horizontal dimensions separately before multiplying. Using
(a * b) // (c * c)is incorrect. - If \(A<C\) or \(B<C\), one of the quotients will be \(0\), so the answer naturally becomes \(0\) without requiring any special conditional branching.
a, b, c = map(int, input().split())
print((a // c) * (b // c))
Source Code
# 問題文から独立に実装: 縦に A//C 個、横に B//C 個並ぶ
a, b, c = map(int, input().split())
print((a // c) * (b // c))
This editorial was generated by gpt-6-astra-medium.
posted:
last update: