問題一覧 > 通常問題

No.1650 Moving Coins

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (AC するまで非表示) / 解いたユーザー数 191
作問者 : chocorusk / テスター : 👑 Kazun
お気に入りにしたユーザー ProblemId : 6723 / 自分の提出
問題文最終更新日: 2021-08-16 07:53:47
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 310 (順位表) の他の問題:

Problem Statement

$10^6$ squares are arranged in a horizontal row. The squares are numbered $1, 2, \ldots , 10^6$ from left to right.

$N$ coins are placed on the squares. Initially, there is $1$ coin on each of the squares $A_1, A_2, \ldots , A_N$. Rusk can perform the following operation any number of times: choose $1$ coin and move it to the square adjacent on its left or right. However, he cannot perform an operation that would result in $2$ or more coins being on the same square, or an operation that would move a coin outside the squares.

Rusk's goal is to reach a state in which there is $1$ coin on each of the squares $B_1, B_2, \ldots , B_N$. Find the minimum number of operations required for this, and find $1$ sequence of operations that achieves this minimum.

Input

$N$
$A_1\ A_2\ \ldots \ A_N$
$B_1\ B_2\ \ldots \ B_N$

  • $1\leq N\leq 2\times 10^5$
  • $1\leq A_1 < A_2 < \ldots < A_N\leq 10^6$
  • $1\leq B_1 < B_2 < \ldots < B_N\leq 10^6$
  • The goal can be achieved in at most $2\times 10^5$ operations.
  • All input values are integers.

Output

Output in the following format.

$M$
$k_1\ c_1$
$k_2\ c_2$
$:$
$k_M\ c_M$
On line $1$, output the minimum number of operations $M$.

On the following $M$ lines, output a sequence of operations that achieves the minimum number of operations. On line $i+1$ ($1\leq i\leq M$), output the integer $k_i$ ($1\leq k_i\leq N$) and the character $c_i$ (L or R) representing the $i$-th operation, separated by a space. This means moving the $k_i$-th coin from the left to the square adjacent on its left if $c_i$ is L, and moving the $k_i$-th coin from the left to the square adjacent on its right if it is R.

If there are multiple sequences of operations satisfying the conditions, you may output any of them.

Sample

Sample 1
Input
2
1 2
2 4
Output
3
2 R
1 R
2 R

  • In operation $1$, move coin $2$ from the left to the square adjacent on its right. There is now one coin on each of the squares $1$, $3$, that is, $1$ coin per square.
  • In operation $2$, move coin $1$ from the left to the square adjacent on its right. There is now one coin on each of the squares $2$, $3$, that is, $1$ coin per square.
  • In operation $3$, move coin $2$ from the left to the square adjacent on its right. There is now one coin on each of the squares $2$, $4$, that is, $1$ coin per square.
The goal cannot be achieved in $2$ or fewer operations, so this output is correct.

On the other hand, the following output is incorrect, because after operation $1$, there would be $2$ coins on square $2$.

Incorrect Output
3
1 R
2 R
2 R
Sample 2
Input
3
999998 999999 1000000
999998 999999 1000000
Output
0

There are cases where no operations need to be performed at all.

Sample 3
Input
4
2 4 7 8
3 4 5 6
Output
5
3 L
1 R
4 L
3 L
4 L

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。