Universal Cup Judging System

Universal Cup

Time Limit: 1 s Memory Limit: 512 MB Total points: 100
Statistics

這是本題的簡單版本。簡單版本與困難版本唯一的差別,是解答中移動次數的限制。

Yuki 住在一個有 $n+1$ 列、$n$ 行的網格上。各列由上至下編號為 $1$ 至 $n+1$,各行由左至右編號為 $1$ 至 $n$。以 $(i,j)$ 表示第 $i$ 列、第 $j$ 行的格子。

網格上有 $n-1$ 個障礙物,其分布滿足以下條件:

  • 第 $1$ 列與第 $n+1$ 列都沒有障礙物。

  • 對所有 $2\le i\le n$,第 $i$ 列恰有一個障礙物。

  • 對所有 $1\le j\le n$,第 $j$ 行至多有一個障礙物。

最初,Yuki 位於 $(1,1)$。她聽說第 $n+1$ 列住著一群袋鼠,因此想前往第 $n+1$ 列欣賞風景。

為了達成目標,Yuki 可以移動數次。每次移動時,她會選擇四個方向(上、下、左、右)之一,並朝該方向移動一格。具體而言,若目標格子在網格之外,或其中有障礙物,便不執行這次移動。

可惜,Yuki 只知道障礙物分布的規則,卻不知道障礙物的確切位置。因此,她希望你幫她指定一個移動序列,使得對於任何合法的障礙物分布,Yuki 都能在某個時刻到達第 $n+1$ 列(她只需至少到達第 $n+1$ 列一次;完成所有移動後,不必留在該列)。

由於 Yuki 並不趕時間,你的解答中的移動次數不得超過 $30\cdot n$。

輸入格式

唯一一行包含一個正整數 $n$($2\le n\le 10^3$)。

輸出格式

第一行輸出一個整數 $k$($1\le k\le30\cdot n$),表示你的解答中的移動次數。

第二行輸出一個長度為 $k$ 的字串 $s$,其中 $s_i$ 表示 Yuki 第 $i$ 次移動的方向:

  • 若 $s_i=\texttt{U}$,Yuki 向上移動。

  • 若 $s_i=\texttt{D}$,Yuki 向下移動。

  • 若 $s_i=\texttt{L}$,Yuki 向左移動。

  • 若 $s_i=\texttt{R}$,Yuki 向右移動。

範例

輸入格式 1

2

輸出格式 1

4
DRDD

輸入格式 2

3

輸出格式 2

17
DDDUUURDDDUUURDDD

說明

對於第一個範例:

  • 以灰色格子表示障礙物,白色格子表示空格。下圖顯示所有滿足要求的障礙物分布:
problem_17353_3540e2b0dea0e6bdac38a8284e6a991a.png
  • 對於第一種障礙物分布,Yuki 的路徑是 $(1,1)\to(1,1)\to(1,2)\to(2,2)\to(3,2)$。

  • 對於第二種障礙物分布,Yuki 的路徑是 $(1,1)\to(2,1)\to(2,1)\to(3,1)\to(3,1)$。

  • 對於每一種合法的障礙物分布,Yuki 都會到達第 $n+1$ 列,因此範例輸出正確。

對於第二個範例:

  • 以灰色格子表示障礙物,白色格子表示空格。下圖顯示所有滿足要求的障礙物分布:
problem_17353_4f3a19c4b58ee0b25c1c95d22ab7a444.png
  • 容易證明,對於這些障礙物分布中的任何一種,按照範例輸出給出的移動方式,Yuki 都會到達第 $n+1$ 列。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.