loj#P550. 「LibreOJ Round #8」Matching
「LibreOJ Round #8」Matching
Description
Given a grid with rows and columns, in this grid, you can choose two different grid points and match them into a pair. Notice that a point can only be matched with no more than one point. It means unmatched points are allowed. We define a weight function for a pair of points as the following form:
$$\begin{aligned} dx &= \left|x_A - x_B\right| \\ dy &= \left|y_A - y_B\right| \\ f(A, B) &= \begin{cases} dx + dy & , dx + dy \geq k \\ 0 & , dx + dy < k \end{cases} \end{aligned} $$The weight of a possible matching scheme is defined as the sum of weights that the matching pairs given. Your task is to calculate the maximum possible weight of all matching schemes.
Input Format
Read from the standard input.
The first line contains a single integer which means the number of the test cases.
Each of the following lines contains three integers which means the height and the width of the grid, and the constant in the weight function.
Output Format
Write to the standard output.
For each test case, output a line containing a single integer — the maximum of the weight of possible matching plans.
4
1 1 0
1 2 0
2 2 1
2 3 1
0
1
4
7
6
23 66 12
233 666 123
2333 6666 1234
23333 6666 1234
2333 66666 1234
23333 66666 12345
33759
34876089
34987610889
1166494448889
2682884270889
34998761108889
4
1 1 0
1 2 0
2 2 1
2 3 1
0
1
4
7
6
23 66 12
233 666 123
2333 6666 1234
23333 6666 1234
2333 66666 1234
23333 66666 12345
33759
34876089
34987610889
1166494448889
2682884270889
34998761108889
Constraints
For all test cases, ,,.
Detailed constraints are as follows (blank grids denote the same constraints as mentioned above):
Subtask# | Score (percentage) | Special Constraints | ||
---|---|---|---|---|
and | ||||
- | ||||
and | ||||
- |