CF1344B Monopole Magnets
题目描述
**单极磁铁**,顾名思义,就是只有一个磁极(N 或 S)的磁铁,~~他们在实际生活中是不存在的,不过……不要在意那些细节。~~
我们有一个 $n$ 行 $m$ 列的方格图,要在里面放一些单极磁铁,你可以随便放置,甚至把多个磁铁放在同一个格子里。
单极磁铁的**吸引**是这么定义的:任选一个 N 极磁铁和一个 S 极磁铁,如果它们两个**恰好处于同一行或同一列中**,那 N 极磁铁会向**靠近 S 极磁铁**的方向**前进一格**。当然,如果它们两个处于同一个格子,什么也不会发生。注意 **S 极磁铁的位置是永远不会变化的**。
这个方格图里的每一个格子都涂成了**黑色**或**白色**。磁铁的放置必须要**遵守以下规则**:
1. 每行每列都必须至少有一个 S 极磁铁。
2. 对于每个黑色格子,必须有某个 N 极磁铁通过一系列的吸引操作经过它。
3. 对于每个白色格子,无论 N 极磁铁的位置怎样变化,都不能经过它。
现在我们想知道:要满足以上三条规则,至少要放几个 N 极磁铁。如果无论怎么放都不能满足规则,请输出 $-1$。
输入格式
无
输出格式
无
说明/提示
In the first test, here is an example placement of magnets:
In the second test, we can show that no required placement of magnets exists. Here are three example placements that fail to meet the requirements. The first example violates rule $ 3 $ since we can move the north magnet down onto a white square. The second example violates rule $ 2 $ since we cannot move the north magnet to the bottom-left black square by any sequence of operations. The third example violates rule $ 1 $ since there is no south magnet in the first column.
In the third test, here is an example placement of magnets. We can show that there is no required placement of magnets with fewer north magnets.
In the fourth test, we can show that no required placement of magnets exists. Here are two example placements that fail to meet the requirements. The first example violates rule $ 1 $ since there is no south magnet in the first row. The second example violates rules $ 1 $ and $ 3 $ since there is no south magnet in the second row and we can move the north magnet up one unit onto a white square.
In the fifth test, we can put the south magnet in each cell and no north magnets. Because there are no black cells, it will be a correct placement.