MagicalSquare
SRM 525 · 2011-05-25 · by ir5
Problem Statement
You are given two
- For all 0<=i<=2, S[i][0]+S[i][1]+S[i][2] = rowStrings[i].
- For all 0<=j<=2, S[0][j]+S[1][j]+S[2][j] = columnStrings[j].
Return the number of ways in which the strings S[i][j] can be chosen so that all conditions are satisfied.
Constraints
- rowStrings and columnStrings will each contain exactly 3 elements.
- Each element of rowStrings will contain between 0 and 50 characters, inclusive.
- Each element of columnStrings will contain between 0 and 50 characters, inclusive.
- rowStrings and columnStrings will contain only lowercase letters ('a'-'z').
{"f", "o", "x"}
{"f", "o", "x"}
Returns: 1
The only valid way to choose the strings: --- --- --- | f | | | --- --- --- | | o | | --- --- --- | | | x | --- --- --- That is, S[0][0]="f", S[1][1]="o", S[2][2]="x", and all other S[i][j] are empty.
{"x", "x", "x"}
{"x", "", "xx"}
Returns: 3
These are the three valid possibilities: --- --- --- --- --- --- --- --- --- | x | | | | | | x | | | | x | --- --- --- --- --- --- --- --- --- | | | x | | x | | | | | | x | --- --- --- --- --- --- --- --- --- | | | x | | | | x | | x | | | --- --- --- --- --- --- --- --- ---
{"cd", "cd", "cd"}
{"dvd", "dvd", "dvd"}
Returns: 0
In this case there is no way to satisfy all conditions.
{"abab", "ab", "abab"}
{"abab", "ab", "abab"}
Returns: 11
{"qwer", "asdf", "zxcv"}
{"qaz", "wsx", "erdfcv"}
Returns: 1
Submissions are judged against all 91 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MagicalSquare with a public method long long getCount(vector<string> rowStrings, vector<string> columnStrings) · 91 test cases · 2 s / 256 MB per case