Editorial for COCI '10 Contest 5 #3 Brodovi
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.
First, let's decrease all given day indices by . This way, a ship with visit period will come to the harbour in days
Let be the first entertaining day after the day . It is clear that there is a ship with visit period . This ship will also arrive to the harbour in days , , etc. Therefore, we no longer need to worry about entertaining days divisible by , since this ship will visit them all.
We repeat this procedure, ignoring the days covered by previously found ships.
When there are no more entertaining days that we must take care of, we are done and the solution is equal to the number of ships found.
Complexity is , because for each ship found ( ships max) we must traverse all the entertaining days ().
Comments