3084.Appleman and Complicated Task

Time Limit: 1s Memory Limit: 256MB

Toastman came up with a very complicated task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?

Given a n \times n checkerboard. Each cell of the board has either character 'x', or character 'o', or nothing. How many ways to fill all the empty cells with 'x' or 'o' (each cell must contain only one character in the end) are there, such that for each cell the number of adjacent cells with 'o' will be even? Find the number of ways modulo 1000000007 (109+7). Two cells of the board are adjacent if they share a side.

Input Format(From the terminal/stdin)

The first line contains two integers n, k (1 \le n,k \le 105) - the size of the board, and the number of cells that has characters initially.

Then k lines follows. The i-th line contains two integers and a character: ai, bi, ci (1 \le ai,bi \le n; ci is either 'o' or 'x'). This line means: there is a character ci in the cell that is located on the intersection of the ai-th row and bi-th column. All the given cells are distinct.

Consider that the rows are numbered from 1 to n from top to bottom. Analogically, the columns are numbered from 1 to n from left to right.

Output Format(To the terminal/stdout)

Print a single integer - the answer to the problem.

Sample Input 1

Copy
3 2
1 1 x
2 2 o
 · \n
 · · \n
 · · \n

Sample Output 1

Copy
2
 \n

Sample Input 2

Copy
4 3
2 4 x
3 4 x
3 2 x
 · \n
 · · \n
 · · \n
 · · \n

Sample Output 2

Copy
2
 \n

Hints

In the first example there are two ways:

 xxo xoo
 xox ooo
 oxx oox

Submit

请先 登录

© 2025 FAQs