SPartition
SRM 528 · 2011-05-25 · by ir5
Problem Statement
Formally, you are given a
- X = (x[0], ..., x[n/2-1]) such that x[0] < x[1] < ... < x[n/2-1].
- Y = (y[0], ..., y[n/2-1]) such that y[0] < y[1] < ... < y[n/2-1].
- {x[0], ..., x[n/2-1], y[0], ..., y[n/2-1]} = {0,1,...,n-1}. That is, each of the values 0 through n-1 is present either in X or in Y.
- For each k such that 0 <= k < n/2 we have s[x[k]] = s[y[k]].
Notes
- You may assume that the return value always fits into a long.
Constraints
- s will contain between 2 and 40 characters, inclusive.
- The number of characters in s will be even.
- Each character of s will be either 'o' or 'x'.
"oxox" Returns: 2
There are two ways to choose the pair of sequences: (x[0], x[1]) = (0, 1), (y[0], y[1]) = (2, 3) (x[0], x[1]) = (2, 3), (y[0], y[1]) = (0, 1)
"oooxxx" Returns: 0
It is possible that there is no valid pair of sequences.
"xoxxox" Returns: 4
The four valid pairs of sequences look as follows: (x[0], x[1], x[2]) = (0, 1, 2), (y[0], y[1], y[2]) = (3, 4, 5) (x[0], x[1], x[2]) = (3, 4, 5), (y[0], y[1], y[2]) = (0, 1, 2) (x[0], x[1], x[2]) = (0, 1, 3), (y[0], y[1], y[2]) = (2, 4, 5) (x[0], x[1], x[2]) = (2, 4, 5), (y[0], y[1], y[2]) = (0, 1, 3)
"xo" Returns: 0
"ooooxoox" Returns: 8
Submissions are judged against all 127 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SPartition with a public method long long getCount(string s) · 127 test cases · 2 s / 256 MB per case