MagicalGirlLevelTwoDivOne
SRM 514 · 2011-05-25 · by wrong
Problem Statement
Magical Girls are girls who have magical powers. They fight against evil witches to protect the Earth.
You, one of the Magical Girls, found a slate palette. You know that the information of an ancient magic is written on the palette. Unfortunately, some parts of the palette are broken, so you cannot read all the information.
The information is indicated by a rectangular grid whose width is W and height is H. Rows are numbered from 0 to H-1 from top to bottom. Columns are numbered from 0 to W-1 from left to right. Each cell of the grid should contain an integer between 1 and 9, inclusive. Now some of the cells are broken and don't contain a digit. You want to know how many ways the empty cells can be filled so that the completed grid meets the following conditions:
- For all integers r and c, where 0 <= r <= H-n and 0 <= c < W, the sum F[r][c] + F[r+1][c] + ... + F[r+n-1][c] must be an odd number. (Here F[r][c] is a number written in the cell whose row number is r and column number is c.)
- For all integers r and c, where 0 <= r < H and 0 <= c <= W-m, the sum F[r][c] + F[r][c+1] + ... + F[r][c+m-1] must be an odd number.
You are given a
Constraints
- palette will contain between 1 and 50 elements, inclusive.
- Each element of palette will contain between 1 and 50 characters, inclusive.
- Each element of palette will contain the same number of characters.
- Each character in palette will be '1', '2', '3', '4', '5', '6', '7', '8', '9', or '.'.
- n will be between 1 and min{10, H}, inclusive, where H is the number of elements in palette.
- m will be between 1 and min{10, W}, inclusive, where W is the number of characters in palette[0].
{"12",
"2."}
2
2
Returns: 5
The missing digit can be filled with '1', '3', '5', '7' or '9'.
{"21",
"1."}
2
2
Returns: 4
This time it can be filled with '2', '4', '6' or '8'.
{"...",
"...",
"..."}
1
1
Returns: 1953125
{"..58..",
"..47.."}
2
3
Returns: 0
It's impossible to fill this grid.
{"...1.2.3",
"4.5.6...",
"...7.8.9",
"1.2.3..."}
4
4
Returns: 886073030
Submissions are judged against all 106 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class MagicalGirlLevelTwoDivOne with a public method int theCount(vector<string> palette, int n, int m) · 106 test cases · 2 s / 256 MB per case