Editorial for CCC '23 S1 - Trianglane


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.

To help Bocchi determine how much tape she needs, we need to do some careful counting.

For the first subtask, we can count B, the number of black triangles, which is the number of times 1 appears in the input. The correct answer will be 3 \times B. Note that we can ignore the second line of input which is also true for the second subtask. However, for this second subtask, there could be adjacent black triangles and Bocchi does not need to place warning tape on the common side in these cases. Notice that each of these common sides contributes two to the value of 3 \times B. This means we obtain the correct final answer by subtracting two from 3 \times B for each pair of adjacent black triangles.

The same principle applies to the third subtask but we also have to look for black triangles that are adjacent but in different rows. These can only occur at even-numbered positions (assuming we start counting at zero).

It is possible to solve this problem without making the observation that you can subtract from 3 \times B. This approach involves looking for all the places where warning tape needs to be placed. An algorithm is needed which includes sides of triangles on the perimeter of the pathway as well as sides between adjacent triangles which are not the same colour.

Regardless of which approach is taken, many solutions to the first three subtasks will be quite efficient. However, the fourth subtask is meant to ensure this by disallowing overly slow solutions. It specifically requires that not too many passes are made over either row. More formally, only a constant number of passes of each row is allowed. Solutions that miss this requirement are probably too slow because they use a built-in function within a loop which itself loops through a row of triangles.


Comments

There are no comments at the moment.