Editorial for Another Contest 3 Problem 3 - Lexicographically Largest Common Subsequence
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lemma: The string is sorted in reverse alphabetic order.
Proof: By contradiction - if the string is not, take the first occurrence of an index where . Deleting character results in a common subsequence that is lexicographically larger.
The solution follows directly from this - if a z
is present in the answer, it must be the first letter, so find the first z
in every string, and delete the prefix of each string up to and including that z
. Repeat until some string doesn't contain a z
. Repeat this process again with y
, and loop through the letters in reverse alphabetic order.
Comments