CF198B.Jumping on Walls
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
瓦西娅正在玩一款忍者主题的电脑游戏。在当前关卡中,瓦西娅所操控的忍者需要逃出一道深邃的峡谷。
该峡谷由两堵垂直且相互平行的墙壁构成,每堵墙的高度均为 $ n $ 米。我们可将每堵墙沿垂直方向划分为若干段长度为 1 米的区域,并从底部开始自下而上用正整数 $ 1 $ 至 $ n $ 对这些区域编号。其中某些区域是安全的,忍者可以攀爬;其余区域布满尖刺,忍者不可停留——我们将这些区域称为“危险区域”。
初始时,忍者位于左侧墙壁最底部(即编号为 $ 1 $)的区域。每一秒,忍者可执行以下三种动作之一:
- 向上攀爬一个区域;
- 向下攀爬一个区域;
- 跳跃至对面墙壁上的某个区域:跳跃后所到达的区域编号,恰好比起跳前所在区域的编号高 $ k $ 米。更准确地说,若跳跃前忍者位于某堵墙的编号为 $ x $ 的区域,则跳跃后他将出现在另一堵墙的编号为 $ x + k $ 的区域。
若在某一时刻,忍者试图抵达编号大于 $ n $ 的区域,则我们认为他已成功逃出峡谷。
此时,峡谷正遭受洪水侵袭,水位每秒上升 1 米。初始时,水位位于编号为 $ 1 $ 的区域的下边界处。忍者不可停留在已被水淹没的区域上。我们可以认为忍者与洪水“交替行动”:先由忍者执行一次动作,随后水位上升 1 米;接着忍者再执行一次动作,如此循环往复。
若忍者成功逃出峡谷,则视为本关卡完成。
在多次失败尝试后,瓦西娅开始怀疑:该关卡是否根本无法完成?请帮助他回答这一问题。
输入格式
The first line contains two integers n and k (1 ≤ n, k ≤ 105) — 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.
第一行包含两个整数 n 和 k(1≤n,k≤105),分别表示峡谷的高度以及忍者的跳跃高度。
第二行描述左侧岩壁——一个长度为 n 的字符串。第 i 个字符表示左侧岩壁第 i 个区域的状态:“X” 表示危险区域,“-” 表示安全区域。
第三行以相同格式描述右侧岩壁。
保证左侧岩壁的第一个区域不是危险区域。
输出格式
Print "YES" (without the quotes) if the ninja can get out from the canyon, otherwise, print "NO" (without the quotes).
如果忍者能够从峡谷中逃脱,则输出 "YES"(不带引号);否则,输出 "NO"(不带引号)。
输入输出样例
输入#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.
在第一个样例中,忍者应首先跳到右侧岩壁,然后沿右侧岩壁向下移动一米,再跳至左侧岩壁。接下来的一跳即可使忍者脱离峡谷。
在第二个样例中,忍者无法以任何方式脱离峡谷。
输入解题思路,AI测评打分。不知道怎么写?