Baltic OI '17 P5 - Plus Minus

View as PDF

Submit solution

Points: 15 (partial)
Time limit: 1.0s
Memory limit: 1G

Problem type
Baltic Olympiad in Informatics: 2017 Day 2, Problem 2

Matthew the physicist studies the quantum electro-dynamics of a silicon-based rectangular microchip. The microchip consists of a very large N \times M grid of electrons. Each electron has either positive (up) or negative (down) spin, denoted by + and - respectively.

Matthew does not know the spin of all the electrons, but he has done K measurements. In the ith measurement, he discovered that the electron at position (y_i, x_i) has a given spin s_i. He also knows that in each 2 \times 2 subgrid, there are equally many electrons with positive and negative spin. He wants to know whether he can recover the state of every electron based on his measurements. If not, he would like to know how many possible states are consistent with his measurements. For classified reasons, he wants the answer modulo 10^9 + 7.

Input Specification

The first line contains three numbers N, M and K: the height of the grid, the width of the grid and the number of measurements. The next K lines contain a spin s_i where s_i is either + or -, and two numbers 1 \le y_i \le N and 1 \le x_i \le M – the coordinates of the electron. Matthew never did two measurements at the exact same location.

Constraints

We always have 1 \le N, M \le 10^9 and 0 \le K \le 100\,000. For subcases, the inputs have these further restrictions:

  • Group 1: 12 points N, M \le 5
  • Group 2: 42 points N, M \le 1\,000
  • Group 3: 46 points No further restrictions.

Output Specification

Output the total number of valid states consistent with Matthew's measurements modulo 10^9 + 7.

Sample Input 1

2 4 4
+ 1 1
- 1 2
+ 1 3
- 1 4

Sample Output 1

2

Explanation for Sample Output 1

The only two valid grids are

+-+-
+-+-

and

+-+-
-+-+

Sample Input 2

3 3 3
- 2 1
+ 2 3
+ 3 3

Sample Output 2

0

Comments

There are no comments at the moment.