#P10608. 双人游戏
双人游戏
Description
Renko has designed a two-player game with two players, Little R and Little M, following these rules:
There is a chessboard. Initially, the board has some black pieces, white pieces, and empty cells. The initial state of the board is described by a string of length , where:
Bindicates a black piece,Windicates a white piece,_indicates an empty cell.
Note: The board may have no empty cells.
Before the game starts, both players receive an operation sequence $O = [\langle c_1, x_1 \rangle, \langle c_2, x_2 \rangle, \ldots, \langle c_m, x_m \rangle]$, where each pair satisfies:
- ,
- is an empty cell at step .
This sequence is public, meaning both players know who will place a piece and where at each step.
During the game, players follow the operation sequence. In the -th step, player places a piece (black or white, chosen by the player) at position . By the end of the game, every cell will have exactly one piece.
Little R aims to maximize the number of maximal consecutive monochromatic segments, while Little M aims to minimize it. Determine the final number of segments when both play optimally. It can be proven that the answer is unique.
Definition: A maximal consecutive monochromatic segment is a pair where , such that:
- All pieces from the -th to -th position are the same color.
- The -th piece (if exists) and the -th piece (if exists) are of a different color.
Input Format
- The first line contains two integers and , where is the number of empty cells.
- The second line contains a string of length , describing the initial board state.
- The next lines each contain a character and an integer , describing the player and the position for the -th step.
Output Format
Output one integer: the number of maximal consecutive monochromatic segments when both players act optimally.
3 2
B__
R 3
M 2
2
3 3
___
R 1
R 3
M 2
2
5 2
BW__B
R 4
R 3
5
Hint
Explanation
Sample #1
The final board is BWW, which is optimal for both players. The number of segments is .
Sample #2
Little R (controlling the first two steps) will place different colors to maximize segments. Little M then places any color. One possible final state is BWW with segments.
This sample satisfies Special Property B.
Sample #3
The final board is BWBWB with segments.
This sample satisfies Special Property A.
Constraints
Bundled testing is used.
$$\def\arraystretch{1.5} \begin{array}{|c|c|c|c|c|}\hline \textbf{Subtask} & \textbf{Points} & \bm{n,m \leq} & \textbf{Special Property} & \textbf{Subtask Dependencies} \cr\hline 1 & 10 & 20 & - & - \cr\hline 2 & 10 & 2 \times 10^5 & \mathbf{A} & - \cr\hline 3 & 20 & 2 \times 10^5 & \mathbf{B} & - \cr\hline 4 & 20 & 10^3 & - & 1 \cr\hline 5 & 40 & 2 \times 10^5 & - & 1,2,3,4 \cr\hline \end{array}$$Special Properties:
- A: All are either
RorM. - B: All characters in are
_.
For all data: , , , and .
Translated by DeepSeek R1
京公网安备 11011102002149号