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.
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 .
- If there is a traffic light that is green, also increase the position and time by .
- If there is a traffic light that is red, increase the time by .
What remains is to determine the light at a traffic light at a given time index . If starts from zero, then a traffic light is red when , and green otherwise.
Comments