Connection Status:
Competition Arena > TheLuckyString
SRM 428 · 2008-12-01 · by Vasyl[alphacom] · Simple Search, Iteration
Class Name: TheLuckyString
Return Type: int
Method Name: count
Arg Types: (string)
Problem Statement

Problem Statement

John and Brus are studying string theory at the university. According to Brus, a string is called lucky if no two consecutive characters are equal. John is analyzing a String s, and he wants to know how many distinct lucky strings can be generated by reordering the letters in s. If s is a lucky string in its original ordering, it should also be considered in the count.

Constraints

  • s will contain between 1 and 10 characters, inclusive.
  • Each character of s will be a lowercase letter ('a' - 'z').
Examples
0)
"ab"
Returns: 2

Two lucky strings - "ab" and "ba".

1)
"aaab"
Returns: 0

It's impossible to construct a lucky string.

2)
"aabbbaa"
Returns: 1

"abababa" is the only lucky string that can be generated.

3)
"abcdefghij"
Returns: 3628800
4)
"zzddvveett"
Returns: 39480

Submissions are judged against all 84 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TheLuckyString with a public method int count(string s) · 84 test cases · 2 s / 256 MB per case

Submitting as anonymous