StringSequences
TCO12 Wildcard Round · 2012-03-27 · by rng_58
Problem Statement
Farmer John and Eel Brus are studying string theory at the university. One day John found a very interesting sequence of strings s1, s2, ..., sK and told Brus about it. Brus only remembers the following information:
- Each string in the sequence consists of lowercase letters only.
- The sequence starts with A. In other words, s1 = A.
- The sequence ends with B. In other words, sK = B.
- For each i between 1 and K-1, inclusive, si+1 can be obtained by inserting one lowercase letter to si. For example, if s1 is "tco", valid options for s2 include "qtco", "trco", "tcso", and "tcot", but not "xco", "txoc", or "srm".
Constraints
- A will contain between 1 and 49 characters, inclusive.
- Each character in A will be a lowercase letter ('a'-'z').
- B will contain between N+1 and 50 characters, inclusive, where N is the number of characters in A.
- Each character in B will be a lowercase letter ('a'-'z').
- There will be at least one sequence that matches Brus's information in the problem statement.
Statement by TopCoder, Inc. — view the original on the archive.
"oxoxox" "foxfoxfox" Returns: 6
The following six sequences match Brus's information: "oxoxox", "foxoxox", "foxfoxox", "foxfoxfox" "oxoxox", "foxoxox", "foxoxfox", "foxfoxfox" "oxoxox", "oxfoxox", "foxfoxox", "foxfoxfox" "oxoxox", "oxfoxox", "oxfoxfox", "foxfoxfox" "oxoxox", "oxoxfox", "foxoxfox", "foxfoxfox" "oxoxox", "oxoxfox", "oxfoxfox", "foxfoxfox"
"aaaaa" "aaaaaaaa" Returns: 1
Only the sequence "aaaaa", "aaaaaa", "aaaaaaa", "aaaaaaaa" matches Brus's information.
"tco" "tcotco" Returns: 18
"a" "alnfrlrealjnsliejsraijneroav" Returns: 135925750
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" Returns: 1
Submissions are judged against all 70 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class StringSequences with a public method int countSequences(string A, string B) · 70 test cases · 2 s / 256 MB per case