Editorial for WC '18 Contest 1 J4 - Germaphobia


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.

Let's define \text{MinDoors}(x, y) to be the minimum number of doors which Bob must pass through to get from classroom x to classroom y. The only options he should consider are to avoid the hallways and pass exclusively through classrooms (which requires |y-x| doors), or to go through the hallway (which always requires 2 doors). Therefore, \text{MinDoors}(x, y) = \min(|y-x|, 2). The total answer is then the sum of \text{MinDoors}(C_i, C_{i+1}) for each i from 1 to M-1, plus an extra 2 (for one door required to get from the hallway to the first class, and another door required to get from the final class to the hallway).


Comments

There are no comments at the moment.