P26986 [AtCoder] Snake Escaping 2
省选
题目描述

Problem Description

In the year 22XX, AtCoder Kingdom is experiencing a massive outbreak of venomous snakes. King chokudai had confined all the discovered snakes in a warehouse, but three years later, the snakes have reappeared in the kingdom.
In the kingdom's square park, there are tiles with colors painted on them. The tiles can be considered as a grid of $ H $ rows and $ W $ columns. The snakes have decided to camouflage themselves with the colors of the tiles to avoid being recaptured.

Today, one snake has escaped into the park. The snake has $ |S| $ segments, and the color of the $ i $-th segment from the head is represented by the $ i $-th character of the string $ S $. $ S $ consists of R, G, and B, which respectively mean red, green, and blue.
In this park, adjacent segments of the snake must be in adjacent squares, either vertically or horizontally.

The snake wants to believe it won't be recaptured, so it asks you to determine if there is any combination of tile colors and snake positions where the snake can perfectly camouflage itself, meaning every segment of the snake matches the color of the tile in its square.
Given the snake's colors, output a possible combination of tile colors and snake positions.

Input Format

The input is given from the standard input in the following format:

$ S $

Output Format

The output should follow the format below:

$ H $ $ W $ $ a_{1,1} $$ a_{1,\ 2} $ ... $ a_{1,\ W} $ $ a_{2,1} $$ a_{2,\ 2} $ ... $ a_{2,\ W} $ : : : $ a_{H,1} $$ a_{H,\ 2} $ ... $ a_{H,\ W} $ $ sx $ $ sy $ $ V $

  • On the first line, output the height $ H $ and width $ W $ of the park.
  • From the second line to the $ H $-th line, output the state of the park $a_{i,\ j}$. $a_{i,\ j}$ must be one of R, G, or B.
  • On the $ H+2 $-th line, output the position of the snake's head ($ sx $, $ sy $). $1\ \leq\ sx\ \leq\ H$, $1\ \leq\ sy\ \leq\ W$ must be satisfied.
  • On the $ H+3 $-th line, output the movement of the snake's second segment and onwards. Output L if the $ i $-th segment is to the left of the $ i-1 $-th segment, R if to the right, D if down, and U if up.
  • $ H $ and $ W $ must be $ 100 $ or less.

Sample Input and Output

Sample Input #1

RGB

Sample Output #1

3 3
RGB
RGB
RGB
1 1
RR

Sample Input #2

GBRBGBR

Sample Output #2

4 3
GBR
RGR
RBR
RRR
1 1
RRLDDD

Sample Input #3

RGBGRGRBRR

Sample Output #3

3 4
RGBG
BRGR
RRRR
1 1
RRRDLLLRD

Notes/Hints

Constraints

  • $ S $ is a string consisting of R, G, and B, with a length between $ 1 $ and $1\ 000\ 000$ characters.
  • $ S $ is a randomly generated string where R, G, and B appear with equal probability.

Subtasks

Subtask $ 1 $ \[$ 80 $ points\]

  • $|S|\ \leq\ 10\ 000$. (10 cases)

Subtask $ 2 $ \[$ 320 $ points\]

  • $|S|\ \leq\ 15\ 000$. (10 + 10 = 20 cases)

Subtask $ 3 $ \[$ 800 $ points\]

  • $|S|\ =\ 1\ 000\ 000$. (20 cases)

However, the score for Subtask 3 is calculated as follows:

  • Let $ L $ be the largest value of $ max(H,W) $ among all test cases. The score is then:
  • $L\ \leq\ 30$: $ 800 $ points.
  • $31\ \leq\ L\ \leq\ 40$: $1470\ -\ 24L$ points.
  • $41\ \leq\ L\ \leq\ 50$: $1270\ -\ 19L$ points.
  • $51\ \leq\ L\ \leq\ 100$: $floor(620\ \times\ 3^{1-\frac{L}{30}}\ +\ 20)$ points.

Additionally, the scores for Subtask 3 with $30\ \leq\ L\ \leq\ 100$ can also be viewed from this link.

Sample Explanation 1

For example, the snake can camouflage as follows:

Sample Explanation 2

For example, the snake can camouflage as follows:

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
RGB
样例输出
3 3 RGB RGB RGB 1 1 RR