CF1215D.Ticket Game
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even.
Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first 2n digits of this ticket is equal to the sum of the last 2n digits.
Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket.
If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally.
Monocarp 和 Bicarp 居住在 Berland,那里每张公交车票均由 n 位数字组成(n 为偶数)。在一次晚间散步中,Monocarp 和 Bicarp 发现了一张部分数字被擦除的车票。被擦除的数字个数为偶数。
Monocarp 和 Bicarp 决定就这张车票进行一场游戏。Monocarp 讨厌“幸运车票”,而 Bicarp 则收集幸运车票。一张车票被称为幸运车票,当且仅当其前 2n 位数字之和等于后 2n 位数字之和。
Monocarp 和 Bicarp 轮流进行操作(Monocarp 先手)。在每一轮中,当前玩家必须将任意一个被擦除的数字替换为 0 到 9 中的任意一个数字。当车票中不再存在被擦除的数字时,游戏结束。
若所有被擦除的数字均被替换为十进制数字后,该车票为幸运车票,则 Bicarp 获胜;否则 Monocarp 获胜。你需要判断:若双方均采取最优策略,谁将获胜?
输入格式
The first line contains one even integer n (2≤n≤2⋅105) — the number of digits in the ticket.
The second line contains a string of n digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the i-th character is "?", then the i-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even.
第一行包含一个偶数整数 n(2≤n≤2⋅105)—— 表示车票的数字位数。
第二行包含一个长度为 n 的字符串,由数字字符和 "?" 字符组成 —— 这是 Monocarp 和 Bicarp 找到的车票。若第 i 个字符为 "?",则表示第 i 位数字已被擦除。注意:该数字可能含有前导零。字符串中 "?" 字符的个数为偶数。
输出格式
If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes).
如果 Monocarp 获胜,输出 "Monocarp"(不带引号)。否则输出 "Bicarp"(不带引号)。
输入输出样例
输入#1
4 0523
输出#1
Bicarp
输入#2
2 ??
输出#2
Bicarp
输入#3
8 ?054??0?
输出#3
Bicarp
输入#4
6 ???00?
输出#4
Monocarp
说明/提示
Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp.
In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.
由于第一个例子中的票中没有问号,因此在游戏开始前就已确定获胜者,获胜者为 Bicarp。
在第二个例子中,Bicarp 同样获胜。当 Monocarp 选择一个被擦除的数字并将其替换为一个新的数字后,Bicarp 可以选择另一个被擦除数字的位置,并将其替换为相同的数字,从而使这张票变为“快乐票”。
输入解题思路,AI测评打分。不知道怎么写?