Editorial for CCC '23 S1 - Trianglane
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 , the number of black triangles, which is the number of times 1 appears in the input. The correct answer will be . 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 . This means we obtain the correct final answer by subtracting two from 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 . 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