#P15892. [COCI 2025/2026 #6] Učionica
[COCI 2025/2026 #6] Učionica
Description
A group of friends enters a classroom. The height of each friend is known, and the heights of all other students already in the classroom are also known.
The classroom can be represented as an grid , where each cell corresponds to a seat. The seat in the -th row and -th column is denoted by . For every seat, we know whether it is already occupied by a student (along with their height) or if it is empty.
The friends want to take seats in the classroom. Each friend occupies exactly one empty seat, and no two friends can sit in the same seat. Additionally, they want to sit next to each other in the same row. More precisely, they choose a row index such that and a column index such that , and sit in the seats . The friends can sit in these seats in any order; they do not have to sit in the order in which their heights were given.
A friend considers a seat suitable only if all students sitting in front of them (i.e., in rows with a smaller index in the same column) are strictly shorter than them, ensuring they have a clear view. The group considers a set of consecutive seats in the same row suitable if they can arrange themselves so that each friend has a clear view.
Considering these conditions, how many suitable sets of seats for the group are there in the classroom?
Input Format
The first line contains three natural numbers , , and () - the number of rows and columns of the classroom and the number of friends.
The second line contains natural numbers - the heights of the friends.
The next lines each contain natural numbers: if , the seat is empty, and if , the seat is occupied by a student of height ().
Output Format
In the first and only line, output a single number - the number of suitable sets of consecutive seats in the same row where the friends can be arranged so that each has a clear view.
3 4 2
2 6
0 0 3 1
8 0 0 0
0 0 1 0
3
2 4 4
5 2 4 3
1 2 3 4
0 0 0 0
1
5 5 3
17 3 17
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
15
Hint
Clarification of the first example:
The two friends can sit in the first and second seats in the first row, in the second and third seats in the second row, or in the third and fourth seats in the second row. So, they can sit in a total of different sets of seats.
Clarification of the second example:
The four friends can sit in the only four available seats if they arrange themselves from shortest to tallest.
Clarification of the third example:
The three friends can sit in any three consecutive seats in the same row since there are no other students in the classroom resulting in a total of valid sitting arrangements.
Scoring
| Subtask | Points | Constraints |
|---|---|---|
| 1 | 11 | |
| 2 | 13 | |
| 3 | 29 | |
| 4 | 57 | No additional constraints. |
京公网安备 11011102002149号