|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||128 MB||8||4||2||33.333%|
Postman Joe is a fitness fanatic. He has a single row of 20 houses on his delivery route, and sets himself a task every day that will require him to walk up and down the row several times. A typical task will look something like this:
3 U3 D2 U1 U6 D4 D5 U7 U9 D5 D3 U5 U4 D2 D5 U8
This means that Joe delivers firstly to house 3, moves 3 houses up the street and delivers to house 6, then moves 2 houses down the street and delivers to house 4, and so on. The houses are numbered sequentially from 1 to 20, house 1 being at the bottom of the street.
Not every house will necessarily receive a delivery each day, but Joe's instructions must never take him to the same house twice, nor take him beyond either end of the row of houses.
To solve this problem, you must write a program to help Joe. It must check that Joe has set himself a legal task and, if so, must report those houses which do not receive a delivery.
Input will consist of a number of tasks that Joe has set, each on a single line. The last line will contain just a # character – that line should not be processed.
Each task represents the deliveries for a single day. Each line starts with a single integer S (1 <=S <= 20) being the first house to which Joe makes a delivery. This is followed by a sequence of letter-number pairs, each separated by a single space. The letter will be U or D, U meaning go up the street (increasing house number), D go down the street. The number will be a single digit integer, stating the number of houses to move.
Output will consist of 1 line for each line of input. If the instructions for the task are legal (ie no house is visited twice, and Joe is not taken beyond either end of the street), output will be a list of houses that do not receive a delivery that day. The list will be in numerical order with a space between each house number. If all houses receive a delivery, output should be the word none.
If the instructions for a task are not legal, output should be the word illegal.
3 U3 D2 U1 U6 D4 D5 U7 U9 D5 D3 U5 U4 D2 D5 U8 8 D7 U5 U6 D9 U2 D4 U9 U3 D2 U7 U2 #
1 8 14 16 illegal
Joe makes 16 deliveries, missing these 4 houses.
The 7th delivery (D4) is to house 1 which received the 2nd delivery.