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.

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 0.

We know the initial (T=0) position P of each ant: P=N1ii1 for the first (left) row and P=N1+I for the other (right).

There are three cases:

  1. If T is less than i, then the ant will not jump over any other ants and will remain in its initial position.
  2. If T is greater than or equal to i+(the number of ants in the other row), then the ant will jump over all of the ants in the other row.
  3. Otherwise, the ant's position will change by Ti.

Comments

There are no comments at the moment.