#P15890. [COCI 2025/2026 #6] Prepisivanje

    ID: 29345 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>图论二分图COCI(克罗地亚)2026

[COCI 2025/2026 #6] Prepisivanje

题目描述

On the eve of an important Croatian language exam, the classroom is already prepared. We can view it as a matrix of dimension n×mn \times m, where each cell represents one seat. Each cell of the matrix can have one of three values:

  • 22 denotes a seat already occupied by well-behaved students. They are responsible and the teacher is not concerned about them.
  • 11 denotes a seat that the teacher has marked as forbidden. No one will sit in those seats.
  • 00 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.

输入格式

The first line contains natural numbers n,mn, m (1n,m801 \le n, m \le 80), as described in the problem statement.

Each of the next nn lines contains mm characters, each being 00, 11, or 22, representing the matrix described in the problem.

输出格式

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

提示

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 n,m4n, m \le 4
2 15 All cells in the matrix will be 00.
3 16 n=2n = 2
4 52 n15n \le 15
5 19 No additional constraints.