J. Mousepad

Codeforces
IDCF10256J
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Dorian found an old mouse laying around the house and is now playing around with it. Dorian's mousepad can be modeled as a matrix with $N$ rows and $M$ columns such that $N * M <= 10^5$. Each cell of the mousepad is either clean which is represented by a $0$, or dirty which is represented by a $1$. He quickly realised $2$ things: the mouse can only be moved horizontally and vertically and it only registers a movement if it realised between $2$ adjacent cells that are both clean! Now Dorian thought of an interesting game: starting from the top left of the matrix, without lifting his mouse from the mousepad and without going outside the bounds, can he trick the mouse into thinking it was moved to some other arbitrary coordinates $-10^5 <= X <= 10^5$ and $-10^5 <= Y <= 10^5$? You should output a sequence of instruction composed of characters $L (e f t)$, $R (i g h t)$, $U (p)$, $D (o w n)$ if it is possible to reach the said coordinates, or $-1$ otherwise. Keep in mind the $Y$ coordinate increases as you go up in the matrix, and the $X$ coordinate increases as you go right. The mouse initially thinks it is at coordinates $(0, 0)$ and you start from the top left corner of the matrix. There is also something strange about Dorian's mousepad, because its extremities are made of a special material, they never get dirty. That is, first and last rows and columns will always be clean. The first line will contain two integers $N$ and $M$: the dimensions of the mousepad. The following $N$ lines will each contain a string of $M$ characters, the description of the mousepad. The last line will contain two integers $X$ and $Y$, the coordinates Dorian wants to reach. For each testcase, you should output one line either a $-1$ if there is no solution, or a string of no more than $10^6$ characters: the instructions for Dorian. These are the coordinates registered by the mouse after each move: (1,0), (1,0), (1,0), (1,0), (1,0), (1,1), (1,2), (1,3), (2,3) ## Input The first line will contain two integers $N$ and $M$: the dimensions of the mousepad.The following $N$ lines will each contain a string of $M$ characters, the description of the mousepad.The last line will contain two integers $X$ and $Y$, the coordinates Dorian wants to reach. ## Output For each testcase, you should output one line either a $-1$ if there is no solution, or a string of no more than $10^6$ characters: the instructions for Dorian. [samples] ## Note These are the coordinates registered by the mouse after each move:(1,0), (1,0), (1,0), (1,0), (1,0), (1,1), (1,2), (1,3), (2,3)
**Definitions** Let $ S_1 = \{s_{1,1}, s_{1,2}, \dots, s_{1,n_1}\} $ be the multiset of creature strengths for the first mage. Let $ S_2 = \{s_{2,1}, s_{2,2}, \dots, s_{2,n_2}\} $ be the multiset of creature strengths for the second mage. **Constraints** 1. $ 3 \leq n_1 \leq 10 $, $ 3 \leq n_2 \leq 10 $ 2. $ 1 \leq s_{1,i} \leq 10 $, $ 1 \leq s_{2,j} \leq 10 $ for all valid indices 3. For $ k = 1 $: $ \mathbb{P}(\text{first mage wins}) > 0.5 $ 4. For $ k = 2 $: $ \mathbb{P}(\text{second mage wins}) > 0.5 $ 5. For $ k = 3 $: $ \mathbb{P}(\text{first mage wins}) > 0.5 $ **Objective** Find $ S_1 $, $ S_2 $ satisfying the above probability conditions for $ k \in \{1,2,3\} $. **Solution** $$ n_1 = 4 \\ S_1 = \{1, 1, 4, 4\} \\ n_2 = 3 \\ S_2 = \{2, 2, 3\} $$
API Response (JSON)
{
  "problem": {
    "name": "J. Mousepad",
    "description": {
      "content": "Dorian found an old mouse laying around the house and is now playing around with it. Dorian's mousepad can be modeled as a matrix with $N$ rows and $M$ columns such that $N * M <= 10^5$. Each cell of ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10256J"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Dorian found an old mouse laying around the house and is now playing around with it. Dorian's mousepad can be modeled as a matrix with $N$ rows and $M$ columns such that $N * M <= 10^5$. Each cell of ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ S_1 = \\{s_{1,1}, s_{1,2}, \\dots, s_{1,n_1}\\} $ be the multiset of creature strengths for the first mage.  \nLet $ S_2 = \\{s_{2,1}, s_{2,2}, \\dots, s_{2,n_2}\\} $ be the multiset ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments