CF1673A.Subtle Substring Subtraction

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Alice and Bob are playing a game with strings. There will be tt rounds in the game. In each round, there will be a string ss 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 ss.

More formally, if there was a string s=s1s2…sks = s_1s_2 \ldots s_k the player can choose a substring slsl+1…sr−1srs_ls_{l+1} \ldots s_{r-1}s_r with length of corresponding parity and remove it. After that the string will become s=s1…sl−1sr+1…sks = 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 a\texttt{a} is 11, the value of b\texttt{b} is 22, the value of c\texttt{c} is 33, …\ldots, and the value of z\texttt{z} is 2626. 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.

爱丽丝和鲍勃正在玩一个字符串游戏。游戏共进行 tt 轮。每轮中,会给出一个由小写英文字母组成的字符串 ss。

爱丽丝先手,双方轮流进行操作。爱丽丝可以移除任意一个长度为偶数(可能为空)的子串;而鲍勃可以移除任意一个长度为奇数的子串。

更准确地说,若当前字符串为 s=s1s2…sks = s_1s_2 \ldots s_k,则玩家可选择一个长度满足对应奇偶性要求的子串 slsl+1…sr−1srs_ls_{l+1} \ldots s_{r-1}s_r 并将其移除。移除后,字符串变为 s=s1…sl−1sr+1…sks = s_1 \ldots s_{l-1}s_{r+1} \ldots s_k。

当字符串变为空时,该轮结束,双方分别计算本轮得分。每位玩家的得分为其所有被移除字符的数值之和。其中,字符 a\texttt{a} 的值为 11,b\texttt{b} 的值为 22,c\texttt{c} 的值为 33,……,z\texttt{z} 的值为 2626。得分更高者赢得该轮。对每一轮,请判断获胜者以及胜者与败者得分之差。假设双方均以最优策略进行游戏,以最大化自身得分。可以证明:平局不可能出现。

输入格式

The first line of input contains a single integer tt (1≤t≤5⋅1041\leq t\leq 5\cdot 10^4) denoting the number of rounds.

Each of the next tt lines contain a single string ss (1≤∣s∣≤2⋅1051\leq |s|\leq 2\cdot 10^5) consisting of lowercase English letters, denoting the string used for the round. Here ∣s∣|s| denotes the length of the string ss.

It is guaranteed that the sum of ∣s∣|s| over all rounds does not exceed 2⋅1052\cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤5⋅1041\leq t\leq 5\cdot 10^4),表示回合数。

接下来的 tt 行,每行包含一个字符串 ss(1≤∣s∣≤2⋅1051\leq |s|\leq 2\cdot 10^5),由小写英文字母组成,表示该回合所用的字符串。其中 ∣s∣|s| 表示字符串 ss 的长度。

保证所有回合中 ∣s∣|s| 的总和不超过 2⋅1052\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.

每轮输出一行,包含一个字符串和一个整数。如果 Alice 赢得该轮,则字符串必须为 "Alice";如果 Bob 赢得该轮,则字符串必须为 "Bob"。该整数必须为双方均以最优策略进行游戏时,两人得分之差。

输入输出样例

  • 输入#1

    5
    aba
    abc
    cba
    n
    codeforces

    输出#1

    Alice 2
    Alice 4
    Alice 4
    Bob 14
    Alice 93

说明/提示

For the first round, "aba"→Alice"aba"→"a"→Bob"a"→""\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=31+2=3. Bob's total score is 11.

For the second round, "abc"→Alice"abc"→"a"→Bob"a"→""\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=52+3=5. Bob's total score is 11.

For the third round, "cba"→Alice"cba"→"a"→Bob"a"→""\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=53+2=5. Bob's total score is 11.

For the fourth round, "n"→Alice"n"→"n"→Bob"n"→""\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 00. Bob's total score is 1414.

For the fifth round, "codeforces"→Alice"codeforces"→""\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=933+15+4+5+6+15+18+3+5+19=93. Bob's total score is 00.

第一轮:"aba"→Alice"aba"→"a"→Bob"a"→""\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 的总得分为 1+2=31+2=3,Bob 的总得分为 11。

第二轮:"abc"→Alice"abc"→"a"→Bob"a"→""\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 的总得分为 2+3=52+3=5,Bob 的总得分为 11。

第三轮:"cba"→Alice"cba"→"a"→Bob"a"→""\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 的总得分为 3+2=53+2=5,Bob 的总得分为 11。

第四轮:"n"→Alice"n"→"n"→Bob"n"→""\texttt{"n"}\xrightarrow{\texttt{Alice}}\texttt{"n"}\xrightarrow{} \texttt{"n"}\xrightarrow{\texttt{Bob}}\texttt{"}{\color{red}{\texttt{n}}}\texttt{"}\xrightarrow{}\texttt{""}。Alice 的总得分为 00,Bob 的总得分为 1414。

第五轮:"codeforces"→Alice"codeforces"→""\texttt{"codeforces"}\xrightarrow{\texttt{Alice}}\texttt{"}{\color{red}{\texttt{codeforces}}}\texttt{"}\xrightarrow{} \texttt{""}。Alice 的总得分为 3+15+4+5+6+15+18+3+5+19=933+15+4+5+6+15+18+3+5+19=93,Bob 的总得分为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页