2172E.md (2359B)
1 Source: https://codeforces.com/problemset/problem/2172/E 2 3 E. Number Maze 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 At the "Number Maze," a mysterious code master stands guard. He blocks the path and smiles, saying: "Brave adventurer, passing through this gate will not be easy! An ancient numeric code, capable of being rearranged into numerous combinations, is in the code master's possession. The traveler must choose two numeric codes from these combinations and show their $x$A$y$B result, or the gate will trap the traveler here forever!" 22 23 The rules of $x$A$y$B are as follows: 24 25 * Each A indicates that a digit in both codes matches in both value and position. 26 * Each B indicates that a digit in both codes matches in value but not position. 27 28 For example: 29 30 | | | | 31 | --- | --- | --- | 32 | Codes Compared | Result | Explanation | 33 | 5234 vs. 5789 | 1A0B | Only the digit $5$ matches in both value and position. | 34 | 5634 vs. 6589 | 0A2B | Digits $5$ and $6$ match only in value but are in different positions. | 35 | 1847 vs. 6149 | 1A1B | The digit $4$ matches in both value and position, while the digit $1$ only matches in value. | 36 37 You are given a base numeric code $n$, which can be one of $\{12, 123, 1234\}$. Consider all possible permutations of the digits of $n$, sorted in ascending order. Let the $j$-th and $k$-th permutations (1-indexed) be the two numeric codes chosen by the traveler. 38 39 Your task is to compare these two permutations and determine their $x$A$y$B result, according to the rules above. 40 41 Input 42 43 Each test contains multiple test cases. The first line contains a single integer $t$, representing the number of tests the code master will conduct. The description of the test cases follows. 44 45 The only line of each test case contains three integers $n$, $j$, and $k$, representing the base numeric code and the indices of the two permutations to be compared, respectively. 46 47 * $1\le t \le 1000$ 48 * $n \in \{12,123,1234\}$ 49 * Both $j$ and $k$ are valid indices of permutations of the digits of $n$. 50 51 Output 52 53 For each test case, output the result in the format $x$A$y$B, where $x$ and $y$ are integers. 54 55 Examples 56 57 Input 58 59 ``` 60 3 61 12 1 2 62 123 1 2 63 123 2 5 64 ``` 65 66 Output 67 68 ``` 69 0A2B 70 1A2B 71 1A2B 72 ``` 73 74 Input 75 76 ``` 77 3 78 1234 15 9 79 1234 1 24 80 1234 1 1 81 ``` 82 83 Output 84 85 ``` 86 2A2B 87 0A4B 88 4A0B 89 ```