Grayscale Photo
Time limit1sMemory limit512 MB
Count the color photos (RGB triples) whose floor average matches each given gray value, modulo 10007.
- Level
Medium6 of 10
- Topics
- Combinatorics, Math, Dynamic programming
- Solved
- No attempts yet
Problem
Mirko got a digital camera as a birthday present and has been taking pictures ever since. Every day he shoots thousands of color photos, and when he gets home he prints them and sticks them on the walls. Mirko's printer is black and white, so every photo stored on the camera has to be turned into its gray version before printing.
The camera stores a photo like this. After the number of rows and the number of columns , the image file holds more numbers. Each pixel is written as three numbers, the intensities of red, green and blue. The intensities are integers from to inclusive. A color pixel becomes the matching shade of gray by averaging those three values.
In the formula, means rounding down. For example, , , .
One day Slavko came to Mirko's studio and teased him: "You don't even know that your printer prints a huge number of different photos the same way!" Mirko then wanted to know what that number is. To be precise, he wants to count the color photos that the formula above turns into the given gray photo. That count can be very large, so report its remainder when divided by .
Input
The first line contains the number of rows and the number of columns of the gray photo. (, )
Each of the next lines contains integers . () These numbers are the gray shade of each pixel.
Output
Print the number of different color photos that give the stated gray photo, modulo .