Facebook
From Chocolate Armadillo, 3 Years ago, written in LaTeX.
Embed
Download Paste or View Raw
Hits: 67
  1. This can be done in constant time using math, but brute force is enough to get the first two test cases. The answer is just #unpainted rows * #unpainted columns, or $(R - r) \cdot (C - c)$ Another way to see this is to use inclusion/exclusion: The number of black squares painted by the rows is: # rows painted (r) x total number of columns (C) The number of black squares painted by the columns is: # columns painted (c) x total number of rows (R) Overlaps were double counted, so we need to subtract r*c The answer is then $RC - (rC + cR - rc)$ which is the same as the above answer