Softmatch
SRM 709 · 2016-12-07 · by subscriber
Problem Statement
- 'a' matches small digits: '0' and '1'
- 'A' matches big digits: '2' and '3'
- 'b' matches even digits: '0' and '2'
- 'B' matches odd digits: '1' and '3'
Constraints
- S will contain between 1 and 50 characters, inclusive.
- Each character in S will be either 'a' or 'b'.
- patterns will contain between 1 and 5 elements, inclusive.
- Each element in patterns will contain between 1 and 50 characters, inclusive.
- Each character in patterns will be between '0' and '3', inclusive.
- Each element in patterns will be at most as long as S.
"aaa"
{"03","21"}
Returns: 2
There are two optimal solutions: You may change S to "AaA". This string contains an occurrence of pattern 1 at position 0 and an occurrence of pattern 0 at position 1. You may change S to "aAa". This string contains an occurrence of pattern 0 at position 0 and an occurrence of pattern 1 at position 1. In either case, the total number of occurrences of a pattern is 2.
"aba"
{"03","11"}
Returns: 3
The string "aBa" contains three occurrences of the given patterns: pattern 0 occurs at position 0, and pattern 1 occurs both at position 0 and at position 1.
"bba"
{"00","00"}
Returns: 4
Even if two patterns are equal, we count the occurrences of each of them separately.
"bbbbbb"
{"1110","011","100"}
Returns: 3
"abbaa"
{"123"}
Returns: 2
Submissions are judged against all 94 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Softmatch with a public method int count(string S, vector<string> patterns) · 94 test cases · 2 s / 256 MB per case