AtCoder Grand Contest 005
翻译中…
Problem Statement
翻译中…
We have a string $X$, which has an even number of characters. Half the characters are S, and the other half are T.
翻译中…
Takahashi, who hates the string ST, will perform the following operation $10^{10000}$ times:
翻译中…
- Among the occurrences of
STin$X$as (contiguous) substrings, remove the leftmost one. If there is no occurrence, do nothing.
翻译中…
Find the eventual length of $X$.
翻译中…
Constraints
翻译中…
$2 ≦ |X| ≦ 200,000$- The length of
$X$is even. - Half the characters in
$X$areS, and the other half areT.
翻译中…
Partial Scores
翻译中…
- In test cases worth
$200$points,$|X| ≦ 200$.
翻译中…
Input
翻译中…
The input is given from Standard Input in the following format:
翻译中…
X
翻译中…
Output
翻译中…
Print the eventual length of $X$.
翻译中…
样例
Input #1
TSTTSS
Output #1
4
In the $1$-st operation, the $2$-nd and $3$-rd characters of `TSTTSS` are removed. $X$ becomes `TTSS`, and since it does not contain `ST` anymore, nothing is done in the remaining $10^{10000}-1$ operations. Thus, the answer is $4$.
Input #2
SSTTST
Output #2
0
$X$ will eventually become an empty string: `SSTTST` ⇒ `STST` ⇒ `ST` ⇒ ``.
Input #3
TSSTTTSS
Output #3
4
$X$ will become: `TSSTTTSS` ⇒ `TSTTSS` ⇒ `TTSS`.
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。