Editorial for Baltic OI '14 P2 - Three Friends
Submitting an official solution before solving the problem yourself is a bannable offence.
Subtask 1
We try removing each of the possible letters, thus simulating all possible cases of string
. For each letter, we construct a new string
, which contains the final string with one letter deleted. We check if
is of the form
, and add
as one of the possible answers. Depending on how many different answers we found, we output the result.
Complexity: For each of letters, we match strings of length
, thus complexity is
.
Subtask 2
The key observation is to notice that the initial string could only be in two of the positions: either
, if the letter was inserted after a first copy of initial string
, or
if the letter was inserted before a second copy of initial string
.
We have to check both cases, to see if initial string is valid. We match it symbol-by-symbol with the remaining substring of
, to see if they only differ by one symbol.
Yet again, depending on how many different answers we found, we output the result.
Complexity: We match two strings of length two times, thus complexity is
.
Comments