codeforces-scrape

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

1220C.md (2060B)


      1 Source: https://codeforces.com/problemset/problem/1220/C
      2 
      3 C. Substring Game in the Lesson
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 mebibytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $s$ and a number $k$ ($0 \le k \lt |s|$).
     22 
     23 At the beginning of the game, players are given a substring of $s$ with left border $l$ and right border $r$, both equal to $k$ (i.e. initially $l=r=k$). Then players start to make moves one by one, according to the following rules:
     24 
     25 * A player chooses $l^{\prime}$ and $r^{\prime}$ so that $l^{\prime} \le l$, $r^{\prime} \ge r$ and $s[l^{\prime}, r^{\prime}]$ is lexicographically less than $s[l, r]$. Then the player changes $l$ and $r$ in this way: $l := l^{\prime}$, $r := r^{\prime}$.
     26 * Ann moves first.
     27 * The player, that can't make a move loses.
     28 
     29 Recall that a substring $s[l, r]$ ($l \le r$) of a string $s$ is a continuous segment of letters from s that starts at position $l$ and ends at position $r$. For example, "ehn" is a substring ($s[3, 5]$) of "aaaehnsvz" and "ahz" is not.
     30 
     31 Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $s$ and $k$.
     32 
     33 Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $s$ and determines the winner for all possible $k$.
     34 
     35 Input
     36 
     37 The first line of the input contains a single string $s$ ($1 \leq |s| \leq 5 \cdot 10^5$) consisting of lowercase English letters.
     38 
     39 Output
     40 
     41 Print $|s|$ lines.
     42 
     43 In the line $i$ write the name of the winner (print Mike or Ann) in the game with string $s$ and $k = i$, if both play optimally
     44 
     45 Examples
     46 
     47 Input
     48 
     49 ```
     50 abba
     51 ```
     52 
     53 Output
     54 
     55 ```
     56 Mike
     57 Ann
     58 Ann
     59 Mike
     60 ```
     61 
     62 Input
     63 
     64 ```
     65 cba
     66 ```
     67 
     68 Output
     69 
     70 ```
     71 Mike
     72 Mike
     73 Mike
     74 ```