A10764 | Ostap and Grasshopper
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length $n$ such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly $k$ cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if $k=1$ the grasshopper can jump to a neighboring cell only, and if $k=2$ the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
Ostap knows that grasshopper is able to jump to any empty cell that is exactly $k$ cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if $k=1$ the grasshopper can jump to a neighboring cell only, and if $k=2$ the grasshopper can jump over a single cell.
Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect.
输入格式
The first line of the input contains two integers $n$ and $k$ ( $2<=n<=100$ , $1<=k<=n-1$ ) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length $n$ consisting of characters '.', '\#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '\#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
The second line contains a string of length $n$ consisting of characters '.', '\#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '\#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once.
输出格式
If there exists a sequence of jumps (each jump of length $k$ ), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes).
输入输出样例
输入 #1
5 2 #G#T#
输出 #1
YES
输入 #2
6 1 T....G
输出 #2
YES
输入 #3
7 3 T..#..G
输出 #3
NO
输入 #4
6 2 ..GT..
输出 #4
NO
In the first sample, the grasshopper can make one jump to the right in order to get from cell $2$ to cell $4$ .
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left $5$ times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left $5$ times.
In the third sample, the grasshopper can't make a single jump.
In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted