QOJ.ac

QOJ

時間限制: 8 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#17528. ローリング・リック

统计

机の上に横 $W$、縦 $H$ の長方形の紙があり、その上に横 $A$、縦 $B$、高さ $C$ の直方体である Rick が置かれている。最初、Rick の底面の左上隅は、紙の左辺および上辺と重なっている。

Rick は右または下に転がすことができる。Rick を転がすときは、底面の右端または下端を軸にして右または下に回転させる。Rick のすべての面には乾いていないペンキが塗られており、Rick が触れた床の領域にペンキが付着する。机を汚さないようにするため、Rick が紙からはみ出すように転がしてはならない。

Rick を適切に転がして、Rick の底面の右下隅が紙の右辺および下辺と重なるように移動させるとき、紙に付着するペンキの領域の面積を最大化せよ。

入力

1行目に Rick のサイズ $A, B, C$ と方眼紙のサイズ $W, H$ が空白区切りで与えられる。($1 \leq A, B, C, W, H \leq 1\,000\,000$; $A < W$; $B < H$)

すべての入力値は整数である。

出力

もし Rick を右下へ移動させることができない場合は、1行目に -1 のみを出力する。

そうでない場合、1行目に紙に付着するペンキの領域の面積の最大値を出力し、2行目に Rick を転がす方法を RD のみからなる文字列で出力する。$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.