A8638 | Jumping on Walls
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is $n$ meters. Let's imagine that we split these walls into $1$ meter-long areas and number them with positive integers from $1$ to $n$ from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
- climb one area up;
- climb one area down;
- jump to the opposite wall. That gets the ninja to the area that is exactly $k$ meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area $x$ of one wall, then after the jump he is located at area $x+k$ of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than $n$ , then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
The canyon consists of two vertical parallel walls, their height is $n$ meters. Let's imagine that we split these walls into $1$ meter-long areas and number them with positive integers from $1$ to $n$ from bottom to top. Some areas are safe and the ninja can climb them. Others are spiky and ninja can't be there. Let's call such areas dangerous.
Initially the ninja is on the lower area of the left wall. He can use each second to perform one of the following actions:
- climb one area up;
- climb one area down;
- jump to the opposite wall. That gets the ninja to the area that is exactly $k$ meters higher than the area he jumped from. More formally, if before the jump the ninja is located at area $x$ of one wall, then after the jump he is located at area $x+k$ of the other wall.
If at some point of time the ninja tries to get to an area with a number larger than $n$ , then we can assume that the ninja got out of the canyon.
The canyon gets flooded and each second the water level raises one meter. Initially the water level is at the lower border of the first area. Ninja cannot be on the area covered by water. We can assume that the ninja and the water "move in turns" — first the ninja performs some action, then the water raises for one meter, then the ninja performs one more action and so on.
The level is considered completed if the ninja manages to get out of the canyon.
After several failed attempts Vasya started to doubt whether it is possible to complete the level at all. Help him answer the question.
输入格式
The first line contains two integers $n$ and $k$ ( $1<=n,k<=10^{5}$ ) — the height of the canyon and the height of ninja's jump, correspondingly.
The second line contains the description of the left wall — a string with the length of $n$ characters. The $i$ -th character represents the state of the $i$ -th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
The second line contains the description of the left wall — a string with the length of $n$ characters. The $i$ -th character represents the state of the $i$ -th wall area: character "X" represents a dangerous area and character "-" represents a safe area.
The third line describes the right wall in the same format.
It is guaranteed that the first area of the left wall is not dangerous.
输出格式
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
输入输出样例
输入 #1
7 3 ---X--X -X--XX-
输出 #1
YES
输入 #2
6 2 --X-X- X--XX-
输出 #2
NO
In the first sample the ninja should first jump to the right wall, then go one meter down along the right wall, then jump to the left wall. The next jump can get the ninja from the canyon.
In the second sample there's no way the ninja can get out of the canyon.
In the second sample there's no way the ninja can get out of the canyon.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted