Editorial for COCI '06 Contest 2 #3 Kolone
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
One approach is to simulate the ants' behaviour second by second.
A more efficient approach directly calculates the final position of each ant.
Let's label the ants with numbers within their rows, starting with
We know the initial (
There are three cases:
- If
is less than , then the ant will not jump over any other ants and will remain in its initial position. - If
is greater than or equal to (the number of ants in the other row), then the ant will jump over all of the ants in the other row. - Otherwise, the ant's position will change by
.
Comments