## Mock CCC '18 Contest 2 J5/S3 - A Coloring Problem

View as PDF

Points: 10 (partial)
Time limit: 5.0s
Memory limit: 1G

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

An -by- grid is good if every square is colored either red or blue, and if the square in row , column is blue, then every square in row , column that satisfies and must also be colored blue.

You are given a grid that is partially colored in. Count the number of ways to color the remaining squares of the grid such that the grid is good.

#### Constraints

At least one square in the grid will be ..

#### Input Specification

The first line contains two space-separated integers and .

Each of the next lines contains characters representing the grid. Each character is either R to represent a red square, B to represent a blue square, or . to indicate a square that has not been colored.

#### Output Specification

Print, on a single line, the number of distinct colorings possible.

#### Sample Input

3 2
..
B.
.R

#### Sample Output

6

#### Sample Input

7 6
......
.....B
.B..R.
......
...B..
.R....
...R..

#### Sample Output

3

#### Sample Input

2 2
R.
.B

#### Sample Output

0