Make String 1
Time limit2sMemory limit1024 MB
Given a string of equal S and U counts, print a sequence of cursor operations that builds it in at most 2N operations.
- Level
Medium6 of 10
- Topics
- String, Implementation, Greedy
- Solved
- No attempts yet
Problem
Seohyun is the teaching assistant in charge of the physics lab this semester, and she is entering the students' grades.
The section she manages has students. Exactly half of them receive S and the other half receive U. is always even.
The grades of student 1, student 2, , student are given as a string of length . Seohyun's job is to enter this string into the grading system.
Seohyun enters the grades by repeating only the following operations.
- Insert
SUat the cursor position. - If the cursor is not at the leftmost position, move the cursor one character to the left.
- Insert
USat the cursor position.
The initial state is an empty string. The cursor is always at the front, at the end, or between two characters. After operations 1 and 3, the cursor moves to just after the inserted string.
For Seohyun, find a way to enter all the grades using at most operations.
Input
The first line contains the length of the string (, is even).
The second line contains the string consisting only of S and U, which represents the grades. has the same number of S and U characters.
Output
On the first line, print the number of operations ().
On the second line, print a string of length describing Seohyun's operations. Operation 1 is written as S, operation 2 as N, and operation 3 as U. When the cursor is at the leftmost position, operation 2 must not be printed.
After all operations, the cursor may be anywhere.
If there are multiple answers, print any one of them.
Under the input constraints, an answer always exists, and this can be proven.