MagicWords
SRM 433 · 2009-01-21 · by gojira_tc
Problem Statement
You are given a
Constraints
- S will contain between 1 and 8 elements, inclusive.
- Each element of S will contain between 1 and 20 characters, inclusive.
- Each element of S will contain only uppercase letters ('A'-'Z').
- K will be between 1 and 200, inclusive.
Statement by TopCoder, Inc. — view the original on the archive.
{"CAD","ABRA","ABRA"}
1
Returns: 6
Every permutation generates a magic word here.
{"AB","RAAB","RA"}
2
Returns: 3
The magic words are "ABRAABRA" and "RAABRAAB". The first word is generated only by the permutation (0, 1, 2), and the second word is generated by the two permutations (1, 2, 0) and (2, 0, 1).
{"AA","AA","AAA","A"}
1
Returns: 0
All permutations generate the string "AAAAAAAA" and it clearly is not a magic word because all its cyclic shifts are the same as the original string.
{"AA","AA","AAA","A","AAA","AAAA"}
15
Returns: 720
{"BA","BC","BAC","C","BC"}
2
Returns: 10
Submissions are judged against all 190 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MagicWords with a public method int count(vector<string> S, int K) · 190 test cases · 2 s / 256 MB per case