#P6234. [eJOI 2019] T形覆盖
[eJOI 2019] T形覆盖
Description
If you have played Tetris, you should have seen the following shape:

We call it a T-shaped tetromino. Its center is marked by .
Manca drew a rectangular grid with rows and columns. Rows are numbered from to , and columns are numbered from to . She marked some cells in the grid as special cells. Then, she wants her friend Nika to help her place T-shaped tetrominoes according to the following rules:
- The number of special cells is the same as the number of T-shaped tetrominoes, and the center of each T-shaped tetromino must be on a special cell in the grid.
- T-shaped tetrominoes must not overlap.
- All parts of all tetrominoes must lie inside the grid.
Note that a T-shaped tetromino has four orientations: .
If no arrangement exists, output No. Otherwise, find an arrangement that maximizes the sum of the numbers in the covered cells, and output this maximum value.
Input Format
The first line contains two integers , representing the number of rows and the number of columns.
The next lines each contain integers. The -th number in the -th line (indexed from ) represents the value in the cell at row and column .
The next line contains one integer , representing the number of special cells.
The next lines each contain two integers , representing the position of the -th special cell.
Output Format
If an arrangement exists, output the maximum possible sum of the numbers in the covered cells. Otherwise, output No.
5 6
7 3 8 1 0 9
4 6 2 5 8 3
1 9 7 3 9 5
2 6 8 4 5 7
3 8 2 7 3 6
3
1 1
2 2
3 4
67
5 6
7 3 8 1 0 9
4 6 2 5 8 3
1 9 7 3 9 5
2 6 8 4 5 7
3 8 2 7 3 6
3
1 1
2 2
3 3
No
Hint
Explanation of Sample Input/Output 1
One optimal arrangement is as follows:
- The tetromino centered at is oriented as .
- The tetromino centered at is oriented as .
- The tetromino centered at is oriented as .
Constraints and Notes
This problem uses bundled testdata and has 7 subtasks.
- Subtask 1 (5 points): , and it is guaranteed that for all , .
- Subtask 2 (10 points): , and it is guaranteed that for all , if , then and share an edge.
- Subtask 3 (10 points): , and it is guaranteed that for all , .
- Subtask 4 (10 points): All special cells are in the same row.
- Subtask 5 (15 points): .
- Subtask 6 (20 points): .
- Subtask 7 (30 points): No additional constraints.
For all testdata: , , , .
Notes
The original problem is from: eJOI2019 Problem C. T - Covering.
The translation is from: LibreOJ。
Translated by ChatGPT 5
京公网安备 11011102002149号