A14992 | Subtle Substring Subtraction
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Alice and Bob are playing a game with strings. There will be $t$ rounds in the game. In each round, there will be a string $s$ consisting of lowercase English letters.
Alice moves first and both the players take alternate turns. Alice is allowed to remove any substring of even length (possibly empty) and Bob is allowed to remove any substring of odd length from $s$ .
More formally, if there was a string $s = s_1s_2 \ldots s_k$ the player can choose a substring $s_ls_{l+1} \ldots s_{r-1}s_r$ with length of corresponding parity and remove it. After that the string will become $s = s_1 \ldots s_{l-1}s_{r+1} \ldots s_k$ .
After the string becomes empty, the round ends and each player calculates his/her score for this round. The score of a player is the sum of values of all characters removed by him/her. The value of $\texttt{a}$ is $1$ , the value of $\texttt{b}$ is $2$ , the value of $\texttt{c}$ is $3$ , $\ldots$ , and the value of $\texttt{z}$ is $26$ . The player with higher score wins the round. For each round, determine the winner and the difference between winner's and loser's scores. Assume that both players play optimally to maximize their score. It can be proved that a draw is impossible.
Alice moves first and both the players take alternate turns. Alice is allowed to remove any substring of even length (possibly empty) and Bob is allowed to remove any substring of odd length from $s$ .
More formally, if there was a string $s = s_1s_2 \ldots s_k$ the player can choose a substring $s_ls_{l+1} \ldots s_{r-1}s_r$ with length of corresponding parity and remove it. After that the string will become $s = s_1 \ldots s_{l-1}s_{r+1} \ldots s_k$ .
After the string becomes empty, the round ends and each player calculates his/her score for this round. The score of a player is the sum of values of all characters removed by him/her. The value of $\texttt{a}$ is $1$ , the value of $\texttt{b}$ is $2$ , the value of $\texttt{c}$ is $3$ , $\ldots$ , and the value of $\texttt{z}$ is $26$ . The player with higher score wins the round. For each round, determine the winner and the difference between winner's and loser's scores. Assume that both players play optimally to maximize their score. It can be proved that a draw is impossible.
输入格式
The first line of input contains a single integer $t$ ( $1\leq t\leq 5\cdot 10^4$ ) denoting the number of rounds.
Each of the next $t$ lines contain a single string $s$ ( $1\leq |s|\leq 2\cdot 10^5$ ) consisting of lowercase English letters, denoting the string used for the round. Here $|s|$ denotes the length of the string $s$ .
It is guaranteed that the sum of $|s|$ over all rounds does not exceed $2\cdot 10^5$ .
Each of the next $t$ lines contain a single string $s$ ( $1\leq |s|\leq 2\cdot 10^5$ ) consisting of lowercase English letters, denoting the string used for the round. Here $|s|$ denotes the length of the string $s$ .
It is guaranteed that the sum of $|s|$ over all rounds does not exceed $2\cdot 10^5$ .
输出格式
For each round, print a single line containing a string and an integer. If Alice wins the round, the string must be "Alice". If Bob wins the round, the string must be "Bob". The integer must be the difference between their scores assuming both players play optimally.
输入输出样例
输入 #1
5 aba abc cba n codeforces
输出 #1
Alice 2 Alice 4 Alice 4 Bob 14 Alice 93
For the first round, $\texttt{"aba"}\xrightarrow{\texttt{Alice}}\texttt{"}{\color{red}{\texttt{ab}}}\texttt{a"}\xrightarrow{} \texttt{"a"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{a}}}\texttt{"}\xrightarrow{}\texttt{""}$ . Alice's total score is $1+2=3$ . Bob's total score is $1$ .
For the second round, $\texttt{"abc"}\xrightarrow{\texttt{Alice}}\texttt{"a}{\color{red}{\texttt{bc}}}\texttt{"}\xrightarrow{} \texttt{"a"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{a}}}\texttt{"}\xrightarrow{}\texttt{""}$ . Alice's total score is $2+3=5$ . Bob's total score is $1$ .
For the third round, $\texttt{"cba"}\xrightarrow{\texttt{Alice}}\texttt{"}{\color{red}{\texttt{cb}}}\texttt{a"}\xrightarrow{} \texttt{"a"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{a}}}\texttt{"}\xrightarrow{}\texttt{""}$ . Alice's total score is $3+2=5$ . Bob's total score is $1$ .
For the fourth round, $\texttt{"n"}\xrightarrow{\texttt{Alice}}\texttt{"n"}\xrightarrow{} \texttt{"n"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{n}}}\texttt{"}\xrightarrow{}\texttt{""}$ . Alice's total score is $0$ . Bob's total score is $14$ .
For the fifth round, $\texttt{"codeforces"}\xrightarrow{\texttt{Alice}}\texttt{"}{\color{red}{\texttt{codeforces}}}\texttt{"}\xrightarrow{} \texttt{""}$ . Alice's total score is $3+15+4+5+6+15+18+3+5+19=93$ . Bob's total score is $0$ .
For the second round, $\texttt{"abc"}\xrightarrow{\texttt{Alice}}\texttt{"a}{\color{red}{\texttt{bc}}}\texttt{"}\xrightarrow{} \texttt{"a"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{a}}}\texttt{"}\xrightarrow{}\texttt{""}$ . Alice's total score is $2+3=5$ . Bob's total score is $1$ .
For the third round, $\texttt{"cba"}\xrightarrow{\texttt{Alice}}\texttt{"}{\color{red}{\texttt{cb}}}\texttt{a"}\xrightarrow{} \texttt{"a"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{a}}}\texttt{"}\xrightarrow{}\texttt{""}$ . Alice's total score is $3+2=5$ . Bob's total score is $1$ .
For the fourth round, $\texttt{"n"}\xrightarrow{\texttt{Alice}}\texttt{"n"}\xrightarrow{} \texttt{"n"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{n}}}\texttt{"}\xrightarrow{}\texttt{""}$ . Alice's total score is $0$ . Bob's total score is $14$ .
For the fifth round, $\texttt{"codeforces"}\xrightarrow{\texttt{Alice}}\texttt{"}{\color{red}{\texttt{codeforces}}}\texttt{"}\xrightarrow{} \texttt{""}$ . Alice's total score is $3+15+4+5+6+15+18+3+5+19=93$ . Bob's total score is $0$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted