

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
縦 行、横 列のグリッドがあります。 このグリッドの上から 行目、左から 列目にあるマスのことを と表記します。
このグリッド上には 枚のコインが落ちており、 個目のコインはマス を通ることで拾うことができます。
あなたの目標は、マス から始めて下か右に マス移動することを繰り返し、できるだけ多くのコインを拾いながらマス まで行くことです。
あなたが拾うことのできるコインの枚数の最大値、およびそれを達成するための移動経路を つ求めてください。
制約
- は互いに相異なる
- 入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。
出力
行出力せよ。
行目には、あなたが拾うことのできるコインの枚数の最大値を出力せよ。
行目には、それを達成するための移動経路の つを長さ の文字列として出力せよ。
ここで、出力する文字列の 文字目は、 回目の移動において下に移動するならば D
、右に移動するならば R
である。
拾うコインの枚数が最大となるような移動経路が複数存在する場合は、そのどれを出力しても良い。
入力例 1Copy
3 4 4 3 3 2 1 2 3 1 4
出力例 1Copy
3 DRRDR
上図のように と移動することで、 にある 枚のコインを拾うことができます。
入力例 2Copy
2 2 2 2 1 1 2
出力例 2Copy
1 DR
RD
という移動経路も正解となります。
入力例 3Copy
10 15 8 2 7 2 9 7 9 10 3 7 11 8 12 9 6 8 1
出力例 3Copy
5 DRRRRRRRRDDDDDRRDRDDRRR
Score : points
Problem Statement
There is a grid with rows and columns. Let denote the cell at the -th row from the top and -th column from the left.
There are coins on this grid, and the -th coin can be picked up by passing through the cell .
Your goal is to start from cell , repeatedly move either down or right by one cell, and reach cell while picking up as many coins as possible.
Find the maximum number of coins you can pick up and one of the paths that achieves this maximum.
Constraints
- are pairwise distinct.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print two lines.
The first line should contain the maximum number of coins you can pick up.
The second line should contain one of the paths that achieves this maximum as a string of length .
The -th character of this string should be D
if the -th move is downward, and R
if it is rightward.
If there are multiple paths that maximize the number of coins picked up, you may print any of them.
Sample Input 1Copy
3 4 4 3 3 2 1 2 3 1 4
Sample Output 1Copy
3 DRRDR
As shown in the figure above, by moving , you can pick up three coins at .
Sample Input 2Copy
2 2 2 2 1 1 2
Sample Output 2Copy
1 DR
The path RD
is also acceptable.
Sample Input 3Copy
10 15 8 2 7 2 9 7 9 10 3 7 11 8 12 9 6 8 1
Sample Output 3Copy
5 DRRRRRRRRDDDDDRRDRDDRRR