#P15890. [COCI 2025/2026 #6] Prepisivanje
[COCI 2025/2026 #6] Prepisivanje
Description
On the eve of an important Croatian language exam, the classroom is already prepared. We can view it as a matrix of dimension , where each cell represents one seat. Each cell of the matrix can have one of three values:
- denotes a seat already occupied by well-behaved students. They are responsible and the teacher is not concerned about them.
- denotes a seat that the teacher has marked as forbidden. No one will sit in those seats.
- denotes an empty seat where mischievous students can sit.
The mischievous students have not arrived yet, but they will come soon. The teacher can decide which empty seats the mischievous students will occupy.
Well-behaved students never cheat, but they can cause mischievous students to cheat if they are adjacent to them. A mischievous student will cheat if they have at least one neighboring student (in one of the four directions: up, down, left, right), whether well-behaved or mischievous.
Determine the maximum total number of students that can be seated in the classroom (including both well-behaved and mischievous students) such that no cheating occurs during the exam.
Input Format
The first line contains natural numbers (), as described in the problem statement.
Each of the next lines contains characters, each being , , or , representing the matrix described in the problem.
Output Format
In the first and only line, output a single number - the maximum total number of students that can be seated in the classroom such that no cheating occurs during the exam.
4 4
0100
0202
1000
2120
6
4 4
0000
0000
0000
0000
8
Hint
Clarification of the second example: The teacher will seat students in the first and third rows in odd-numbered columns, and in the second and fourth rows in even-numbered columns. This way, she will ensure that no student can cheat.
Scoring
| Subtask | Points | Constraints |
|---|---|---|
| 1 | 8 | |
| 2 | 15 | All cells in the matrix will be . |
| 3 | 16 | |
| 4 | 52 | |
| 5 | 19 | No additional constraints. |
京公网安备 11011102002149号