chetanrns's blog

By chetanrns, history, 7 years ago, In English

I was trying to solve 1A - Theatre Square PROBLEM STATEMENT Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.

What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. INPUT The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).

OUTPUT Write the needed number of flagstones.

EXAMPLES input 6 6 4 output 4

We have to find the minimum number of flagstones that cover the rectangle.Acording to me, Area of the rectangle=n*m 1 flagstone covers the area of a*a, Since we are not allowed to break the flagstones Minimum number of flagstones that cover the entire area should be ceil( n*m / a*a),ie (total area of the rectangle)/(area covered by single flagstone) But I'm getting WA.Can someone please explain why the above method is wrong.

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

consider a simple case where m=3,n=3 and a=2.

say square looks like this(0 for not filled and 1 for filled)

0 0 0

0 0 0

0 0 0

by putting 2 x 2 square on top right corner,

1 1 0

1 1 0

0 0 0

Here is where it gets tricky...

when you say ceil(n*m/a*a) you are essentially dividing the 2 x 2 square into two pieces of 2 x 1 and filling the remaining squares except the bottom left one.. so you are breaking the squares..

try something else(checking lengths maybe?) or you can always check the editorial :)

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You need ceil(n/a) to cover width of rectangle and ceil(m/a) to cover height of rectangle, so answer is ceil(n/a)*ceil(m/a)