ThreeSameLetters
TCO18 Fun 1B · 2018-04-20 · by misof
Problem Statement
A string is called a block if it consists of exactly three equal letters.
A string is called a one-block string if it contains exactly one contiguous substring that is a block.
For example:
- "aaa" and "abcccdd" are one-block strings
- "noblocks" and "ababab" are not one-block strings, as they do not contain any blocks
- "xxxyyyzzz" and "baaaad" are not one-block strings, as each of them contains at least two blocks
Note that the two blocks in "baaaad" overlap partially.
You are given the
Constraints
- L will be between 1 and 26, inclusive.
- S will be between 1 and 26, inclusive.
3 7 Returns: 7
The seven one-block strings are "aaa", "bbb", "ccc", ..., "ggg".
4 2 Returns: 4
The four one-block strings are "aaab", "abbb", "baaa", and "bbba".
2 17 Returns: 0
10 11 Returns: 410199993
Don't forget to do the calculations modulo 10^9 + 7.
26 26 Returns: 450838424
Submissions are judged against all 106 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ThreeSameLetters with a public method int countStrings(int L, int S) · 106 test cases · 2 s / 256 MB per case