A8645 | Infinite Maze
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
We've got a rectangular $n×m$ -cell maze. Each cell is either passable, or is a wall (impassable). A little boy found the maze and cyclically tiled a plane with it so that the plane became an infinite maze. Now on this plane cell $(x,y)$ is a wall if and only if cell  is a wall.
In this problem  is a remainder of dividing number $a$ by number $b$ .
The little boy stood at some cell on the plane and he wondered whether he can walk infinitely far away from his starting position. From cell $(x,y)$ he can go to one of the following cells: $(x,y-1)$ , $(x,y+1)$ , $(x-1,y)$ and $(x+1,y)$ , provided that the cell he goes to is not a wall.
In this problem  is a remainder of dividing number $a$ by number $b$ .
The little boy stood at some cell on the plane and he wondered whether he can walk infinitely far away from his starting position. From cell $(x,y)$ he can go to one of the following cells: $(x,y-1)$ , $(x,y+1)$ , $(x-1,y)$ and $(x+1,y)$ , provided that the cell he goes to is not a wall.
输入格式
The first line contains two space-separated integers $n$ and $m$ ( $1<=n,m<=1500$ ) — the height and the width of the maze that the boy used to cyclically tile the plane.
Each of the next $n$ lines contains $m$ characters — the description of the labyrinth. Each character is either a "\#", that marks a wall, a ".", that marks a passable cell, or an "S", that marks the little boy's starting point.
The starting point is a passable cell. It is guaranteed that character "S" occurs exactly once in the input.
Each of the next $n$ lines contains $m$ characters — the description of the labyrinth. Each character is either a "\#", that marks a wall, a ".", that marks a passable cell, or an "S", that marks the little boy's starting point.
The starting point is a passable cell. It is guaranteed that character "S" occurs exactly once in the input.
输出格式
Print "Yes" (without the quotes), if the little boy can walk infinitely far from the starting point. Otherwise, print "No" (without the quotes).
输入输出样例
输入 #1
5 4 ##.# ##S# #..# #.## #..#
输出 #1
Yes
输入 #2
5 4 ##.# ##S# #..# ..#. #.##
输出 #2
No
In the first sample the little boy can go up for infinitely long as there is a "clear path" that goes vertically. He just needs to repeat the following steps infinitely: up, up, left, up, up, right, up.
In the second sample the vertical path is blocked. The path to the left doesn't work, too — the next "copy" of the maze traps the boy.
In the second sample the vertical path is blocked. The path to the left doesn't work, too — the next "copy" of the maze traps the boy.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted