FarStrings
SRM 617 · 2013-12-22 · by ir5
Problem Statement
Given two strings S and T, their edit distance is defined as the smallest number of steps in which we can change S to T. In each step, we are allowed to make one of the following changes:
- Erasing one arbitrary character of S.
- Inserting one arbitrary character anywhere into S (including its beginning or end).
- Replacing one arbitrary character of S by a different character.
For example:
- The edit distance between "color" and "coord" is 2.
- The edit distance between "banana" and "bnn" is 3.
- The edit distance between "aaaa" and "bbbb" is 4.
You are given a
Notes
- You may assume that for each valid test case there is at least one n-character string with each of the required edit distances.
Constraints
- t will contain between 1 and 25 characters, inclusive.
- Each character in t will be a lowercase English letter ('a'-'z').
"atan"
Returns: {"aaan", "aaaa", "aaba", "babb" }
Let d(s,u) denote the edit distance between the strings s and u. The return value shown above is correct because: d("atan", "aaan") = 1: we can change 't' to 'a'. d("atan", "aaaa") = 2: we can change 't' to 'a' and then 'n' to 'a'. d("atan", "aaba") = 3: one shortest sequence of changes is "atan" -> "aan" -> "aab" -> "aaba". d("atan", "babb") = 4: one shortest sequence of changes is "atan" -> "aan" -> "ban" -> "bab" -> "babb". The strings "aaan", "aaaa", "aaba", and "babb" are the lexicographically smallest strings with the given edit distance from "atan".
"ir"
Returns: {"ar", "aa" }
"aaa"
Returns: {"aab", "abb", "bbb" }
"bazinga"
Returns: {"aazinga", "aaainga", "aaaanga", "aaaaaga", "aaaaaaa", "aaaaaab", "abbaabb" }
"bcdab"
Returns: {"acdab", "aadab", "aaaab", "aaaaa", "aaaca" }
Submissions are judged against all 163 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FarStrings with a public method vector<string> find(string t) · 163 test cases · 2 s / 256 MB per case