CF910A.The Way to Home

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

A frog lives on the axis OxOx and needs to reach home which is in the point nn . She starts from the point 11 . The frog can jump to the right at a distance not more than dd . So, after she jumped from the point xx she can reach the point x+ax+a , where aa is an integer from 11 to dd .

For each point from 11 to nn 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 11 and nn .

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

输入格式

The first line contains two integers nn and dd ( 2<=n<=1002<=n<=100 , 1<=d<=n11<=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 ss of length nn , consisting of zeros and ones. If a character of the string ss 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 ss equal to one.

输出格式

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 nn from the point 11 .

输入输出样例

  • 输入#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 11 to the point 44 (the length of the jump is three), and the second jump from the point 44 to the point 88 (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.

首页