AlternativePiles
SRM 615 · 2013-12-22 · by snuke
Problem Statement
You are also given an
Guts wants to color each white card red, green, or blue in such a way that the number of cards not colored blue is exactly 2*D*M for some non-negative integer D. Additionally, there must be exactly M sequences of integers S_0 through S_{M-1} with the following properties:
- For each i, the sequence S_i contains exactly 2*D integers, each of them between 0 and N-1, inclusive.
- For each i, the sequence S_i is strictly increasing. That is, S_i[0] < S_i[1] < ... < S_i[2*D-1].
- For each i and each even j, the card S_i[j] is red.
- For each i and each odd j, the card S_i[j] is green.
- No two sequences share a common element. Hence, for each index x of a non-blue card there is precisely one pair (i,j) such that S_i[j]=x.
Constraints
- C will contain between 1 and 5,000 characters, inclusive.
- Each character of C will be 'R', 'G', 'B' or 'W'.
- M will be between 1 and 50, inclusive.
"WRGWWRGW" 2 Returns: 3
There are three valid colorings: "RRGRGRGG", "RRGGRRGG", and "BRGBBRGB". For "RRGRGRGG", we have D=2 and one possibility is to select S_0 = {0,2,3,7} and S_1 = {1,4,5,6}. For "BRGBBRGB", we have D=1 and to show that this is a valid coloring we let S_0 = {5,6} and S_1 = {1,2}.
"RRGG" 1 Returns: 0
There is no valid way.
"BBBB" 5 Returns: 1
Note that D can be zero. Also, note that even though there are no white cards in this test case, there is a valid way to color all white cards: we do nothing and keep the colors we currently have.
"WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW" 50 Returns: 265470435
Do not forget to calculate the answer modulo 10^9 + 7.
"W" 1 Returns: 1
Submissions are judged against all 74 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AlternativePiles with a public method int count(string C, int M) · 74 test cases · 2 s / 256 MB per case