APIO '11 P1 - Table Coloring

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 1.0s
Memory limit: 256M

Problem types

Sam and his sister Sara have a table of n×m square cells. they want to color all of the cells in red or blue. Due to personal beliefs, they want every 2×2 square of the table to have odd number of red cells (i.e. 1 or 3). For example, a valid coloring of a 3×5 table is drawn in the figure below.

Copy
B B R B R
R B B B B
R R B R B

Unfortunately, last night, someone had colored some of the cells of the table with red and some of the others with blue! Sam and Sara are wondering whether they can color the rest of the table such that no 2×2 square contain an even number of red cells.

Input Specification

The first line of input contains three integers, n, m and k, respectively the number of rows and columns of the table and the number of initially-colored cells. The following k lines contain a description of the colored cells. The ith line of this section contains three integers xi, yi, and ci, where xi and yi are the row number of column number of the ith initially-colored cell and ci shows the color of the cell. ci is equal to 1 if that cell is colored in red and it is equal to 0 if the cell is colored in blue. It is guaranteed that these k cells have distinct positions.

Output Specification

In a single line, write the number of possible ways of coloring the table (say W) modulo 109 (i.e. if W is greater than or equal to 109, write its remainder in division by 109).

Constraints

  • For each description of initially colored cells, it is guaranteed that 1xin and 1yim.
  • Consider 2n,m105 and 0k105 in all of the test cases.
  • In 20% of tests n,m5 and k5.
  • In 50% of tests, n,m5000 and k25

Sample Input

Copy
3 4 3
2 2 1
1 2 0
2 3 1

Sample Output

Copy
8

Comments


  • 0
    abednego  commented on Dec. 20, 2023, 4:25 p.m.

    Test inputs 10, 12, 14, 16, and 18 seem wrong. And the official solution on the USACO forums seems to have off-by-one errors. Please check.


    • 3
      xiaowuc1  commented on Dec. 24, 2023, 4:14 a.m.

      The test data have been validated and cross-referenced using this blog post and several other reputable online judges. If you have further concerns, please use the "report an issue" functionality.


    • 1
      htoshiro  commented on Dec. 21, 2023, 11:57 a.m.

      people have solved the question???