Atto Round 1 (Codeforces Round 1041, Div. 1 + Div. 2)
B
Hamiiid, Haaamid... Hamid?
Codeforces
1300
原题
← AC →
翻译中…

Mani has locked Hamid in a $1 \times n$ grid. Initially, some cells of the grid contain walls and the rest are empty, and Hamid is in an empty cell.

翻译中…

In each day, the following events happen in order:

翻译中…
  1. Mani selects an empty cell and builds a wall in that cell. Note that he can not build a wall in the cell which Hamid currently is at;
  2. Hamid selects a direction (left or right), then
  • If there are no walls in that direction, he will escape the grid;
    • Otherwise, he will move to the nearest wall in that direction and destroy that wall. Hamid is at the position of the destroyed wall after this day.
翻译中…

Here is an example of a possible sequence of actions when $n=6$:

翻译中…

image

翻译中…

Hamid is always aware of where the walls are. He wants to minimize the number of days that he needs to escape the grid, while Mani wants to maximize it.

翻译中…

You have to determine the number of days Hamid needs to escape the grid if they both act optimally.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $x$ ($2 \leq n \leq 2 \cdot 10^5$, $1 \leq x \leq n$) — the size of the grid and the initial position of Hamid. He is at the $x$-th cell from left to right initially.

翻译中…

The second line contains a string $s$ of length $n$ ($s_i=\texttt{"#"}$ or $\texttt{"."}$) — the initial state of the grid. The $i$-th cell of the grid contains a wall if $s_i= \texttt{"#"}$, and it is empty if $s_i=\texttt{"."}$.

翻译中…

It is guaranteed that the $x$-th cell is empty, and there are at least two empty cells in the grid.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of days Hamid needs to escape the grid if they both act optimally.

翻译中…

Note

翻译中…

In the first test case, Mani must build a wall in cell $2$, so Hamid can escape from the left side of the grid on the first day.

翻译中…

In the second test case, if Mani places the wall to the left of Hamid, Hamid can escape from the right. And if the wall is to Hamid's right, he can escape from the left. Thus, the answer is $1$.

翻译中…

In the third test case:

翻译中…

image

翻译中…

It can be shown that both players acted optimally in the above illustration.

翻译中…

In the fourth test case, we have shown an example of actions in the statements. Note that the players did not act optimally in this example.

翻译中…

样例

Input #1
4
3 1
..#
4 2
....
5 3
##..#
6 4
#...#.
Output #1
1
1
3
3
InputCopy OutputCopy
题目信息
题号
2127B
时间限制
1 s
内存限制
256 MB
标签
博弈论
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。