#GD0000153. Rô-bốt đi trên tuyết (Snow Walking Robot)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Rô-bốt đi trên tuyết (Snow Walking Robot)
Snow Walking Robot
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A robot starts at on an infinite grid. Its instruction string contains only L, R, U, D. You may delete some instructions and reorder the rest.
Create the longest valid closed walk: it must return to , visit no other cell more than once, and visit the origin only at the start and end. The empty walk is allowed.
Input
The input contains one nonempty string using only L, R, U, D.
Output
Print the maximum retained length and then a valid walk of exactly instructions using no direction more often than in . The second line may be empty when .
Subtasks
- Subtask 1 (20 points): ; every character is
L,R,UorD. - Subtask 2 (30 points): ; every character is
L,R,UorD. - Subtask 3 (50 points): ; every character is
L,R,UorD.
Examples
Input
LRU
Output
2
LR
Explanation
The input LRU has one L, one R and one U, but no D. The two-instruction walk LR returns to the origin and visits no cell twice except the origin. No longer closed walk is possible.