1931E.md (2906B)
1 Source: https://codeforces.com/problemset/problem/1931/E 2 3 E. Anna and the Valentine's Day Gift 4 5 time limit per test 6 7 2 seconds 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 Sasha gave Anna a list $a$ of $n$ integers for Valentine's Day. Anna doesn't need this list, so she suggests destroying it by playing a game. 22 23 Players take turns. Sasha is a gentleman, so he gives Anna the right to make the first move. 24 25 * On her turn, Anna must choose an element $a_i$ from the list and reverse the sequence of its digits. For example, if Anna chose the element with a value of $42$, it would become $24$; if Anna chose the element with a value of $1580$, it would become $851$. Note that leading zeros are removed. After such a turn, the number of elements in the list does not change. 26 * On his turn, Sasha must extract two elements $a_i$ and $a_j$ ($i \ne j$) from the list, concatenate them in any order and insert the result back into the list. For example, if Sasha chose the elements equal to $2007$ and $19$, he would remove these two elements from the list and add the integer $200719$ or $192007$. After such a turn, the number of elements in the list decreases by $1$. 27 28 Players can't skip turns. The game ends when Sasha can't make a move, i.e. after Anna's move there is exactly one number left in the list. If this integer is not less than $10^m$ (i.e., $\ge 10^m$), Sasha wins. Otherwise, Anna wins. 29 30 It can be shown that the game will always end. Determine who will win if both players play optimally. 31 32 Input 33 34 The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases. 35 36 Then follows the description of the test cases. 37 38 The first line of each test case contains integers $n$, $m$ ($1 \le n \le 2 \cdot 10^5$, $0 \le m \le 2 \cdot 10^6$) — the number of integers in the list and the parameter determining when Sasha wins. 39 40 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the list that Sasha gave to Anna. 41 42 It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$. 43 44 Output 45 46 For each test case, output: 47 48 * "Sasha", if Sasha wins with optimal play; 49 * "Anna", if Anna wins with optimal play. 50 51 Example 52 53 Input 54 55 ``` 56 9 57 58 2 2 59 60 14 2 61 62 3 5 63 64 9 56 1 65 66 4 10 67 68 1 2007 800 1580 69 70 4 5 71 72 5000 123 30 4 73 74 10 10 75 76 6 4 6 2 3 1 10 9 10 7 77 78 1 1 79 80 6 81 82 1 1 83 84 10 85 86 8 9 87 88 1 2 9 10 10 2 10 2 89 90 4 5 91 92 10 10 10 10 93 ``` 94 95 Output 96 97 ``` 98 Sasha 99 Anna 100 Anna 101 Sasha 102 Sasha 103 Anna 104 Anna 105 Anna 106 Sasha 107 ``` 108 109 Note 110 111 Consider the first test case. 112 113 Anna can reverse the integer $2$, then Sasha can concatenate the integers $2$ and $14$, obtaining the integer $214$, which is greater than $10^2 = 100$. If Anna had reversed the integer $14$, Sasha would have concatenated the integers $41$ and $2$, obtaining the integer $412$, which is greater than $10^2 = 100$. Anna has no other possible moves, so she loses.