Editorial for COCI '07 Contest 6 #2 Semafori


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.

Simulation suffices for this task too. Two parameters are relevant; where we are and what time it is.

Until we reach the end of the road, do:

  • If there is no traffic light at the current position, increase the position and time by 1.
  • If there is a traffic light that is green, also increase the position and time by 1.
  • If there is a traffic light that is red, increase the time by 1.

What remains is to determine the light at a traffic light at a given time index T. If T starts from zero, then a traffic light is red when T \bmod (R+G) < R, and green otherwise.


Comments

There are no comments at the moment.