QOJ.ac

QOJ

Time Limit: 8 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#17528. 滾動的瑞克

Statistics

桌上有一個寬為 $W$、高為 $H$ 的長方形紙張,紙上放置了一個寬為 $A$、高為 $B$、深為 $C$ 的長方體 Rick。最初,Rick 底面的左邊緣與上邊緣分別與紙張的左邊與上邊重合。

我們可以將 Rick 向右或向下翻滾。翻滾時,Rick 會繞著其底面的右邊緣或下邊緣進行旋轉。由於 Rick 的所有表面都沾有未乾的油漆,因此與 Rick 接觸的紙張區域會沾上油漆。為了保持桌面整潔,Rick 在翻滾過程中不得超出紙張範圍。

請找出適當的翻滾方式,將 Rick 移動至其底面的右邊緣與下邊緣分別與紙張的右邊與下邊重合,並使紙張上沾有油漆的區域面積最大化。

輸入格式

第一行包含 Rick 的尺寸 $A, B, C$ 以及方格紙的尺寸 $W, H$,各數值間以空白分隔。($1 \leq A, B, C, W, H \leq 1\,000\,000$; $A < W$; $B < H$)

所有輸入值皆為整數。

輸出格式

如果無法將 Rick 移動到右下角,請在第一行輸出 -1

否則,請在第一行輸出紙張上沾有油漆區域面積的最大值,並在第二行輸出一個僅由 RD 組成的字串,表示翻滾 Rick 的方式。第 $i$ 個字元若為 R,表示第 $i$ 次將 Rick 向右翻滾;若為 D,則表示向下翻滾。

若有多種可行方案,輸出其中任意一種即可。

範例

輸入 1

1 1 1 24 10

輸出 1

33
RRRRRRRRRRRRRRRRRRRRRRRDDDDDDDDD

輸入 2

3 4 5 6 7

輸出 2

-1

輸入 3

3 4 5 12 12

輸出 3

79
RDRD

說明

下圖為第 3 個範例中 Rick 翻滾的示意圖。

在此範例中,Rick 也可以按照向下、向右、向下、向右的順序翻滾,但該方式沾上油漆的區域面積為 $74$,並非最大值。

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.