XorBoard
SRM 555 · 2012-06-05 · by wrong
Problem Statement
Fox Jiro has a rectangular grid with H rows and W columns (i.e., the grid has H*W cells in total). Initially, each cell in the grid contained the character '0'.
A row flip is an operation in which Jiro picks a row of the grid, and in that row he changes all '0's to '1's and vice versa. Similarly, a column flip is an operation in which Jiro does the same to a column of the grid. Jiro took the grid that contained '0's everywhere. He performed a row flip Rcount times, and then a column flip Ccount times. (It is possible that Jiro flipped the same row or column multiple times.) At the end, Jiro noticed that there are exactly S '1's in the grid.
You are given the
Constraints
- H will be between 1 and 1,555, inclusive.
- W will be between 1 and 1,555, inclusive.
- Rcount will be between 0 and 1,555, inclusive.
- Ccount will be between 0 and 1,555, inclusive.
- S will be between 0 and H*W, inclusive.
2 2 2 2 4 Returns: 4
In two of the four ways, Jiro flips each row once, and then the same column twice. In the other two ways he first flips the same row twice, and then each column once.
2 2 0 0 1 Returns: 0
Without any flips, all cells still contain '0's, so S=1 is impossible.
10 20 50 40 200 Returns: 333759825
Rcount and Ccount may be greater than H and W.
1200 1000 800 600 4000 Returns: 96859710
555 555 555 555 5550 Returns: 549361755
1555 1555 1555 1555 1186490 Returns: 337179150
60 possible choices for (odd rows, odd columns)
1554 1554 1555 1555 1207458 Returns: 394435170
3109 choices
Submissions are judged against all 115 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class XorBoard with a public method int count(int H, int W, int Rcount, int Ccount, int S) · 115 test cases · 2 s / 256 MB per case