CF910A.The Way to Home

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a is an integer from 1 to d.

For each point from 1 to n is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and n.

Determine the minimal number of jumps that the frog needs to reach home which is in the point n from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1.

一只青蛙生活在 OxOx 轴上,需要到达位于点 nn 的家。它从点 11 出发。青蛙每次向右跳跃的距离至多为 dd。也就是说,若青蛙从点 xx 起跳,则可到达点 x+ax + a,其中 aa 是 11 到 dd 之间的整数。

对于从 11 到 nn 的每个点,已知该点上是否有一朵睡莲。青蛙只能跳到有睡莲的点上。保证点 11 和点 nn 上均有睡莲。

请确定青蛙从点 11 出发、到达位于点 nn 的家所需的最少跳跃次数。初始时青蛙位于点 11。若青蛙无法到达家,则输出 −1-1。

输入格式

The first line contains two integers n and d (2 ≤ n ≤ 100, 1 ≤ d ≤ n - 1) — the point, which the frog wants to reach, and the maximal length of the frog jump.

The second line contains a string s of length n, consisting of zeros and ones. If a character of the string s equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string s equal to one.

第一行包含两个整数 nn 和 dd(2 ≤ n ≤ 1002 \leq n \leq 100,1 ≤ d ≤ n − 11 \leq d \leq n - 1)—— 分别表示青蛙希望到达的位置,以及青蛙单次跳跃的最大长度。

第二行包含一个长度为 nn 的字符串 ss,由字符 0 和 1 组成。若字符串 ss 的某个字符为 0,则对应位置上没有荷叶;否则(即该字符为 1),对应位置上有一片荷叶。保证字符串 ss 的第一个和最后一个字符均为 1。

输出格式

If the frog can not reach the home, print -1.

In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point n from the point 1.

如果青蛙无法到达家,则输出 -1。

否则,输出青蛙从点 1 到达位于点 n 的家所需的最少跳跃次数。

输入输出样例

  • 输入#1

    8 4
    10010101

    输出#1

    2
  • 输入#2

    4 2
    1001

    输出#2

    -1
  • 输入#3

    8 4
    11100101

    输出#3

    3
  • 输入#4

    12 3
    101111100101

    输出#4

    4

说明/提示

In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).

In the second example the frog can not reach home, because to make it she need to jump on a distance three, but the maximum length of her jump equals to two.

在第一个例子中,青蛙可以通过两次跳跃到达家:第一次跳跃从点 1 跳到点 4(跳跃长度为 3),第二次跳跃从点 4 跳到点 8(跳跃长度为 4)。

在第二个例子中,青蛙无法到达家,因为要到达家她需要跳跃距离 3,但她跳跃的最大长度仅为 2。

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

首页