Editorial for DMOPC '19 Contest 1 P5 - Broken String
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
For subtask 1, it suffices to print out the string achieved by appending all the strings together.
Time complexity:
For subtask 2, we can use a bitmask-DP to create such a string. If we have (where is a bitmask for which strings were already used) represent whether or not it's possible to create a string with the chosen strings in , where the last string chosen was the one. Thus, we have as if and only if at least one of is where is a string that has a suffix equivalent to the prefix of . This can be checked in time by looping through all the given strings.
Time complexity:
For subtasks 3 and 4, we can represent the given strings as a graph where each node represents a given length string, and each string is an edge connecting its length prefix to its length suffix. Thus, a solution string is represented by an Euler path or an Euler circuit in the graph. For subtask 3, we only need to determine the existence of an Euler path/circuit, while to get full points, we must determine a possible Euler circuit in the graph.
Time complexity: or
Comments