Editorial for DMOPC '19 Contest 1 P5 - Broken String


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.

Author: KevinWan

For subtask 1, it suffices to print out the string achieved by appending all the strings together.

Time complexity: \mathcal{O}(N)

For subtask 2, we can use a bitmask-DP to create such a string. If we have dp[i][mask] (where mask 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 mask, where the last string chosen was the i^\text{th} one. Thus, we have dp[i][mask] as 1 if and only if at least one of dp[j][mask-(2^i)] is 1 where s_j is a string that has a suffix equivalent to the prefix of s_i. This can be checked in \mathcal{O}(N) time by looping through all the given strings.

Time complexity: \mathcal{O}(N^2 2^N)

For subtasks 3 and 4, we can represent the given strings as a graph where each node represents a given K-1 length string, and each string is an edge connecting its K-1 length prefix to its K-1 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: \mathcal{O}(NK) or \mathcal{O}(26^{K-1}+NK)


Comments

There are no comments at the moment.