B - Painting the Wall Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 266 点

問題文

高橋君は、横一列に並んだ N 個のマスからなる壁を塗装しようとしています。

マスには左から順に 1 から N までの番号が付けられています。

はじめ、すべてのマスはペンキで塗られていません。

各マスに障害物があるかどうかは、長さ N の文字列 S によって表されます。

S の i 文字目が # のときマス i には障害物があり、. のときマス i には障害物がありません。

高橋君は幅 K のローラーを使って、以下の操作を何回でも行うことができます。

  • 障害物のない連続する K 個のマスを選び、それらをすべてペンキで塗る。

厳密には、1 \leq i \leq N - K + 1 かつマス i, i+1, \dots, i+K-1 のいずれにも障害物がない(すなわち、S の i 文字目から i+K-1 文字目までがすべて . である)ような整数 i を選び、マス i, i+1, \dots, i+K-1 をすべてペンキで塗る。

同じマスを複数回塗っても構いません。

高橋君の目標は、障害物のないすべてのマスが 1 回以上塗られた状態にすることです。

目標を達成するために必要な操作回数の最小値を求めてください。ただし、目標を達成することが不可能な場合は -1 を出力してください。

なお、はじめから障害物のないマスが 1 つも存在しない場合、すでに目標は達成されているとみなし、必要な操作回数は 0 回とします。

制約

  • 1 \leq N \leq 2 \times 10^6
  • 1 \leq K \leq N
  • S は . および # のみからなる長さ N の文字列
  • N, K は整数

入力

入力は以下の形式で与えられる。

N K
S

出力

目標を達成するために必要な操作回数の最小値を出力せよ。ただし、目標を達成することが不可能な場合は -1 を出力せよ。


入力例 1

8 3
...#....

出力例 1

3

入力例 2

7 3
..#....

出力例 2

-1

入力例 3

25 4
#....##.......#....#.....

出力例 3

6

入力例 4

65 5
.....#..........##.....#...............#......#........##########

出力例 4

11

入力例 5

4 3
####

出力例 5

0

Score : 266 pts

Problem Statement

Takahashi is trying to paint a wall consisting of N squares arranged in a horizontal row.

The squares are numbered 1 to N from left to right.

Initially, no square is painted.

Whether each square has an obstacle is represented by a string S of length N.

If the i-th character of S is #, square i has an obstacle; if it is ., square i does not have an obstacle.

Using a roller of width K, Takahashi can perform the following operation any number of times:

  • Choose K consecutive squares without obstacles and paint all of them.

Strictly speaking, choose an integer i such that 1 \leq i \leq N - K + 1 and none of the squares i, i+1, \dots, i+K-1 have an obstacle (that is, the i-th through (i+K-1)-th characters of S are all .), and paint all squares i, i+1, \dots, i+K-1.

A square may be painted multiple times.

Takahashi's goal is to reach a state where every square without an obstacle has been painted at least once.

Find the minimum number of operations required to achieve this goal. If it is impossible to achieve the goal, output -1.

Note that if there are no obstacle-free squares from the beginning, the goal is considered already achieved, and the required number of operations is 0.

Constraints

  • 1 \leq N \leq 2 \times 10^6
  • 1 \leq K \leq N
  • S is a string of length N consisting of . and #.
  • N and K are integers.

Input

The input is given from Standard Input in the following format:

N K
S

Output

Print the minimum number of operations required to achieve the goal. If it is impossible to achieve the goal, print -1.


Sample Input 1

8 3
...#....

Sample Output 1

3

Sample Input 2

7 3
..#....

Sample Output 2

-1

Sample Input 3

25 4
#....##.......#....#.....

Sample Output 3

6

Sample Input 4

65 5
.....#..........##.....#...............#......#........##########

Sample Output 4

11

Sample Input 5

4 3
####

Sample Output 5

0