QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100

#15968. 点亮灯泡

Statistics

Casper 正在一个 $N \times M$ 的矩形网格板上设计一个电子电路。板上有 $N \times M$ 个与网格对齐的正方形瓷砖。每个瓷砖的四个角中,有两个对角由一根导线连接。

电源连接在网格板的左上角。灯泡连接在网格板的右下角。只有当存在一条连接电源和灯泡的导线路径时,灯泡才会亮起。为了点亮灯泡,可以将任意数量的瓷砖旋转 $90^\circ$(顺时针或逆时针方向均可)。

在上图中,灯泡是熄灭的。如果将右数第二列中的任意一块瓷砖旋转 $90^\circ$,电源和灯泡就会接通,灯泡就会亮起。

编写一个程序,求出为了点亮灯泡,最少需要将多少块瓷砖旋转 $90^\circ$。

输入格式

输入的第一行包含两个整数 $N$ 和 $M$,表示网格板的尺寸。

在接下来的 $N$ 行中,每行包含 $M$ 个字符——要么是 \,要么是 /——表示连接对应瓷砖对角的导线方向。

输出格式

输出必须正好只有一行。如果可以点亮灯泡,该行必须只包含一个整数:点亮灯泡所需旋转的瓷砖的最少数量。如果无法点亮,输出字符串:NO SOLUTION

数据范围

$1 \le N, M \le 500$。

在占 40 分的测试用例中,$1 \le N \le 4$ 且 $1 \le M \le 5$。

样例

输入样例 1

3 5
\\/\\
\\///
/\\\\

输出样例 1

1

说明

样例输入与上图对应。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.