CF735A.Ostap and Grasshopper

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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)用一只随身携带的、装在特制盒子中的蚱蜢来消磨时间。奥斯塔普构建了一条长度为 $ n $ 的直线,该直线中某些格子为空,另一些格子则放置了障碍物。接着,他将蚱蜢放在某个空格子中,再将一只小昆虫放在另一个空格子中。蚱蜢想要吃到这只昆虫。

奥斯塔普知道,蚱蜢每次跳跃可以恰好向左或向右移动 $ k $ 个格子,到达任意一个空格子(注意:中间经过的格子是否为空并不影响跳跃,因为蚱蜢是直接跳过它们的)。例如,若 $ k = 1 $,蚱蜢只能跳到相邻的格子;若 $ k = 2 $,蚱蜢可跳过一个格子。

你的任务是判断:是否存在一系列跳跃,使得蚱蜢能从其初始位置出发,最终到达有昆虫所在的格子。

输入格式

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.

输入的第一行包含两个整数 nn 和 kk(2≤n≤1002 \leq n \leq 100,1≤k≤n−11 \leq k \leq n-1)——分别表示直线上的格子数量以及蚱蜢单次跳跃的长度。

第二行包含一个长度为 nn 的字符串,由字符 .、#、G 和 T 组成。字符 . 表示对应格子为空;字符 # 表示对应格子有障碍物,蚱蜢无法跳至该格子;字符 G 表示蚱蜢的起始位置;字符 T 表示目标昆虫所在位置。保证该字符串中恰好出现一次字符 G 和一次字符 T。

输出格式

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).

如果存在一系列跳跃(每次跳跃长度为 kk),使得蚱蜢能从初始位置跳到有昆虫的格子,则在输入的唯一一行中输出 "YES"(不带引号);否则,输出 "NO"(不带引号)。

输入输出样例

  • 输入#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.

在第一个样例中,蚱蜢可以向右跳跃一次,从而从第 2 个格子到达第 4 个格子。

在第二个样例中,蚱蜢只能跳到相邻的格子,但通往昆虫的道路是畅通的——他可以通过向左跳跃 5 次到达昆虫所在位置。

在第三个样例中,蚱蜢无法完成任何一次跳跃。

在第四个样例中,蚱蜢只能跳到下标为奇数的格子,因此他无法到达昆虫所在位置。

输入解题思路,AI测评打分。不知道怎么写?

首页