QOJ.ac

QOJ

시간 제한: 1 s 메모리 제한: 1024 MB 총점: 100

#14082. 铁路奔跑者

통계

Mario 决定在有史以来最酷的游戏“Railway Runner”中智取关卡。但一如既往,他需要你的帮助。

给定一个铁路图案,他想知道是否有可能从一端到达另一端。输入由 $N$ 行水平线给出,每行包含三个字符,表示三条铁路。每个单元格可以是 “*”——火车的一部分,“.”——铁轨,以及 “/”——通往火车车顶的梯子。你从第一行单元格的地面(铁轨)上开始,你的目标是到达轨道的尽头,即第 $N$ 行的单元格。以下是游戏规则:

  • 你可以在相邻的两辆火车(“*”)或两条铁轨(“.”)之间左右移动,但不能后退(向上)。不允许进行对角线移动。
  • 你只能从相邻的火车或通过梯子(“/”)登上火车。
  • 你可以从火车车顶跳下到铁轨上而不会受伤。你不能从火车跳到相邻的轨道上。
  • 假设输入是合法的(即每个梯子后面都紧跟着一辆火车,前面都紧跟着一条铁轨)。
  • 你可以在第一行的任意一列开始,只要该位置是铁轨(“.”)。你可以在最后一行的任意一列结束,没有其他限制。
  • 在梯子上时,你必须向前移动到相应的火车车顶并爬上梯子。

图 1:第一个样例的示意图

输入格式

输入的第一行包含一个整数 $N$ ($1 \le N \le 100\,000$),表示你正在奔跑的铁路长度。

接下来有 $N$ 行输入,表示每一行的单元格。每行是由 3 个字符组成的序列,字符选自 *./,分别代表火车、铁轨或梯子。

输出格式

输出一行,包含字符串 “YES” 或 “NO”,取决于你是否能到达铁路的另一端。

样例

输入样例 1

10
*.*
*..
**/
..*
.**
.**
/**
***
*..
.**

输出样例 1

YES

输入样例 2

16
...
///
***
...
*.*
./.
.*.
.*.
.*.
.*.
.*.
/./
***
***
***
...

输出样例 2

NO

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.