After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown below, n = 3 and m = 3. There are n + m = 6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are n·m = 9 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move). Assume that both players play optimally. Who will win the game? Input The first line of input contains two space-separated integers, n and m (1 ≤ n, m ≤ 100). Output Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. Examples input 2 2 output Malvika input 2 3 output Malvika input 3 3 output Akshat |
|
|
|
|
Although the rules do not state it explicitly, it appears that when a stick is removed, all of the other intersection points related to the stick go with it. So, if you have 3 horizontal sticks (H1, H2, H3) and 3 vertical sticks (V1, V2, V3), the 9 intersection points are (H1, V1), (H1, V2), (H1, V3), (H2, V1), (H2, V2), (H2,V3), (H3, V1), (H3, V2), and (H3,V3). Say you take away the sticks at (H2, V2)--so you take away H2 and V2. that means that in addition to the selected intersection, the following intersections also disappear: (H1, V2), (H2, V1), (H2, V3), and (H3, V2). So, the remaining intersections are only those related to the remaining sticks. When all of the horizontal sticks OR all of the vertical sticks have been removed, there will be no more intersections, and the result will be known. Since each round both a horizontal and a vertical stick are removed, the number of rounds to determine the result is the smaller of the number of vertical and horizontal sticks. Since there are 2 players, the players alternate turns. Akshat takes the first turn, Malvika takes the second turn, Akshat the third, Malvika the fourth and so on. So, every odd number turn is taken by Akshat and every even number turn is taken by Malvika. So, if there are an odd number of possible turns, Akshat takes the last turn and wins. Likewise, if there are an even number of possible turns, Malvika takes the last turn and wins. So, line 8 determines how many moves are required to determine the winner. Then, line 9 uses the modulo operator to determine if this number is divisible by 2 (result == 0, even) or not (result == 1, odd). Based on whether number of moves is even or not, the winner is declared. That is why the second code snippet works. |
So, line 8 determines how many moves are required to determine the winner. |
Question: Why is the min function used for the N & M why can't I just use n % 0 or m % 0 instead? |
When all of the horizontal sticks OR all of the vertical sticks have been removed, there will be no more intersections, and the result will be known. Since each round both a horizontal and a vertical stick are removed, the number of rounds to determine the result is the smaller of the number of vertical and horizontal sticks. |
I don't really know how to better explain it than that. What that means is that you ARE using n%2 or m%2, but you don't know which one until you do the min operation. If this does not make sense to you, explain how you would like to "just use n % 0 or m % 0 instead?" so I understand what you are asking. |