Editorial for TSOC '15 Contest 2 #2 - Diamonds


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Author: omaewamoushindeiru

Before the explanation: the problem has no tricks and no corner cases, since H is guaranteed to be odd. Thus if the algorithm performs correctly, you will AC all test cases.

Now, a reasonable way to solve this problem would be to have two for loops (one for the top of the diamond, the other for the bottom). To figure out how many asterisks we have to put on i^\text{th} line, consider how far we are in the loop. The number of asterisks can be found using the equation: height / 2 - i and the number of spaces 2i+1. This is really all you need to do to solve this 5 point problem.

Time Complexity: \mathcal O(H^2)


Comments

There are no comments at the moment.