Cipizz

Time limit: 1.3s Memory limit: 1024MB Input: Output:

Following the international success of the Cipizz pizzeria in Craiova, the 33 good friends Dani, Andrei and Ștefan have each decided to open a new pizzeria of their own in Romanescu Park. The park is represented as a binary matrix with NN rows and MM columns (indexed from 11), where 00 means a free cell, and 11 indicates the presence of a tree. Each of them wants to place his pizzeria in a free cell (a cell marked with 00). The park in the image will be represented as follows:

Moreover, there is a villain, Chilly Willy, who wants to sabotage their pizzerias, which is why they have decided to place their pizzerias at 33 distinct points such that each of them has the other 22 pizzerias in sight, meaning that for any two pizzerias, there must be no tree on the straight line between them. Also, in order to maximize their profit, the 33 of them have deduced that the optimal placement of the pizzerias must form an isosceles right triangle with one leg on a row, one leg on a column, with the hypotenuse on a pseudo-diagonal parallel to the main diagonal, and with the 90°90\degree angle at the bottom-left corner. Below you can see a few examples of such valid placements:

Requirement

To make a long story short, Bogdănel is responsible for handling all of this, and he asks you to find out in how many ways we can place the 33 pizzerias so that the mentioned criteria are respected (or, formally, how many triangles of the required shape, with an all-00 perimeter, exist in this binary matrix).

Implementation Details

You must implement the function

int count_triangles(int N, int M, std::vector<int> x, std::vector<int> y);

which receives as parameters:

  • NN and MM, the dimensions of the matrix;
  • xx and yy, vectors of size KK, meaning that there is a tree in the matrix at position (xi,yi)(x_i, y_i) for 0i<K0 \leq i < K.

The function must return the number of ways the 33 pizzerias can be placed, modulo 1 000 000 0071 \ 000 \ 000 \ 007. The judge will call the function exactly once per test.

Constraints and Notes

  • 1N,M1 000 000 0001 \leq N, M \leq 1 \ 000 \ 000 \ 000
  • 0K5 0000 \leq K \leq 5 \ 000
  • 0KNM0 \leq K \leq N \cdot M
  • 1xiN1 \leq x_i \leq N and 1yiM1 \leq y_i \leq M,  0i<K\forall \ 0 \leq i < K
  • The positions of the trees are distinct.
# Score Constraints
1 2 1NM1001 \leq N \leq M \leq 100
2 3 1N,M5001 \leq N, M \leq 500
3 14 1N,M2 0001 \leq N, M \leq 2 \ 000
4 7 1N301 \leq N \leq 30
5 7 N=MN = M and xi=yi, 0i<Kx_i = y_i, \forall \ 0 \leq i < K
6 5 K=0K = 0
7 31 0K500 \leq K \leq 50
8 7 0K2000 \leq K \leq 200
9 9 0K1 0000 \leq K \leq 1 \ 000
10 15 No additional restrictions.

Example

input

3 7 3
2 2
1 6
2 4

output

6

Explanation

Here are the 6 possible solutions:

0000x10  0000x10  0000010  0000010  0000010  0000010
0101xx0  0101xx0  x101000  01x1000  0101x00  01010x0
0000000  0000xxx  xx00000  00xx000  0000xx0  00000xx

Log in or sign up to be able to send submissions!