BlockDistance
SRM 306 · 2006-06-08 · by soul-net
Problem Statement
The block distance from oldText to newText is defined as the least number of block insertions in oldText that are needed to make it equal to newText. A block insertion into oldText is the insertion of any string at any position. For example, if oldText is "herld" a possible block insertion is inserting "llo wo" before the 'r' which will give "hello world".
As an example, if oldText is "hello goodbye" and newText is "hello, how are you? goodbye have a nice day", the block distance between them is 2 because by inserting ", how are you? " and " have a nice day" properly, we can make oldText equal to newText.
You will be given oldText and newText as two
Constraints
- oldText and newText will each have between 1 and 20 elements, inclusive.
- Each element of oldText and newText will have between 1 and 50 characters, inclusive.
- Each character of each element of oldText and newText will have an ASCII value between 32 and 126, inclusive.
{"hello goodbye"}
{"hello, how are you? goodbye have a nice day"}
Returns: 2
The example from the problem statement.
{"aaaaa"}
{"ababababa"}
Returns: 4
Every b has to be added in a different block.
{"aaaaaaaaaaaaaaaa"}
{"aaaaaaaaaaaaaaaa","t","aaaaaaaaaaaaaaaa"}
Returns: 1
{"no way"}
{"No way!"}
Returns: -1
{"x"}
{"x"}
Returns: 0
{"abce","f","ij","klm","n","op","uvwx","z"}
{"ab","cdefg","hijklmnop","q","rs","tuv","wxyz"}
Returns: 4
You need to insert "d" before the 'e', "gh" before the 'i', "qrst" before the 'u' and "y" before the 'z'.
Submissions are judged against all 101 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BlockDistance with a public method int minDist(vector<string> oldText, vector<string> newText) · 101 test cases · 2 s / 256 MB per case