公式

A - Bracket Game 解説 by evima


If \(S\) is not a correct bracket sequence, Taro can win by declaring termination on the first turn. Below, we consider the case where \(S\) is a correct bracket sequence.

When \(S\) is a correct bracket sequence, the length of \(S\) is even, so the length of \(S\) just before Jiro’s operation is always odd. Therefore, even if Jiro declares termination, he will always lose, so only Taro has the possibility of declaring termination.

Also, if \(K\) is odd, Taro can always win by not declaring termination, letting the game continue until \(|S|=K\). Below, we only consider the case where \(K\) is even.

Here, an important fact is that for any correct bracket sequence \(S\), when Taro deletes the first or last character and passes it to Jiro, there is at most one action Jiro can take to restore it to a correct bracket sequence.

When \(S\) begins with (( and ends with ))

If Taro deletes the first character, Jiro deletes the last character, and if Taro deletes the last character, Jiro deletes the first character, so the next state is uniquely determined (note that Jiro is not necessarily able to restore \(S\) to a correct bracket sequence).

Otherwise

Taro’s optimal strategy is to choose the side (first or last) with fewer consecutive () and delete from there. For example, when \(S\) is ()(())()(), Taro and Jiro delete the first (), and \(S\) becomes (())()(). Then, deleting the first character again will break the correct bracket sequence.

In this way, if Jiro can maintain a correct bracket sequence until the length of \(S\) becomes \(K\), Jiro wins; otherwise, Taro wins.

投稿日時:
最終更新: