No.3395 Range Flipping Game
タグ : / 解いたユーザー数 92
作問者 : 👑
AwashAmityOak
nikoro256
🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄🎄
Problem Statement
You are given a string $S$ of length $N$ consisting of A and B.
Alice and Bob play a game using $S$.
Alice and then Bob, in this order, each perform the following operation exactly $\bm 1$ time.
Do one of the following.
- Choose a pair of integers $(l, r)$ satisfying $1 \leq l \leq r \leq N$.
For each character from the $l$-th through the $r$-th character of $S$, changeAtoBandBtoA.
- Do nothing.
Alice's goal is to make the final $S$ as lexicographically small as possible, and Bob's goal is to make the final $S$ lexicographically large.
Find the final $S$ when both players play optimally$\color{red}^{*1}$.
You are given $T$ test cases; answer each of them.
$\color{red}^{*1}$ What it means for both players to play optimally (click to open)
It can be shown that there exists exactly one string $X$ of length $N$ consisting of A and B that satisfies all of the following.
- No matter how Bob performs his operation, Alice can make the final $S$ lexicographically less than or equal to $X$ by playing the game appropriately.
- No matter how Alice performs her operation, Bob can make the final $S$ lexicographically greater than or equal to $X$ by playing the game appropriately.
This $X$ is defined to be the final $S$ when both players play optimally.
Constraints
- $1 \leq T \leq 125000$
- $1 \leq N \leq 250000$
- $S$ is a string of length $N$ consisting of
AandB - $T, N$ are integers
- The sum of $N$ in a single input file does not exceed $500000$
Input
The input is given from standard input in the following format, where the $t$-th test case $(1 \leq t \leq T)$ is denoted by $\mathrm{case}_t$.
$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$
Each test case is given in the following format.
$N$ $S$
Output
Print $T$ lines. The $t$-th line $(1 \leq t \leq T)$ should contain the answer for the $t$-th test case.
Sample
Sample
Input
3 8 ABABBBAB 1 A 16 AAAABBBBAAAABBBB
Output
BBAAAAAB B BBAABBBBAAAABBBB
For the $1$-st test case, the game may proceed as follows, for example.
- Alice chooses $(l, r) = (4, 6)$. $S$ is updated to
ABAAAAAB. - Bob chooses $(l, r) = (1, 1)$. $S$ is updated to
BBAAAAAB.
For the $2$-nd test case, no matter how Alice performs her operation, Bob can make $S$ into B.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。