Editorial for COCI '19 Contest 6 #5 Trener
Submitting an official solution before solving the problem yourself is a bannable offence.
For the first subtask, you could have checked each possibility. The complexity is .
For the next two subtasks, it was necessary to build a directed acyclic graph (DAG) and count the number of paths from nodes on the first level to the nodes on the last level. This can be done using dynamic programming and we leave it as an exercise to the reader. Let's describe what kind of DAG will be built.
On each of the levels, we will have a node for each distinct surname with length equal to that level. The value of that node is equal to the number of surnames it represents. The edges are built naturally – from nodes on level towards nodes on level . Edge from node to node exists if surname in node is different in exactly one letter from surname in node . Depending on how efficient you have built this DAG, you could have scored only the second subtask or the full score.
Comments