codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1215D.md (2220B)


      1 Source: https://codeforces.com/problemset/problem/1215/D
      2 
      3 D. Ticket Game
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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 $\frac{n}{2}$ digits of this ticket is equal to the sum of the last $\frac{n}{2}$ digits.
     24 
     25 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.
     26 
     27 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.
     28 
     29 Input
     30 
     31 The first line contains one even integer $n$ $(2 \le n \le 2 \cdot 10^{5})$ — the number of digits in the ticket.
     32 
     33 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.
     34 
     35 Output
     36 
     37 If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes).
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 4
     45 0523
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 Bicarp
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 2
     58 ??
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 Bicarp
     65 ```
     66 
     67 Input
     68 
     69 ```
     70 8
     71 ?054??0?
     72 ```
     73 
     74 Output
     75 
     76 ```
     77 Bicarp
     78 ```
     79 
     80 Input
     81 
     82 ```
     83 6
     84 ???00?
     85 ```
     86 
     87 Output
     88 
     89 ```
     90 Monocarp
     91 ```
     92 
     93 Note
     94 
     95 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.
     96 
     97 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.