Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 7 点
注意
この問題に対する言及は、2021/4/24 18:00 JST まで禁止されています。言及がなされた場合、賠償が請求される可能性があります。 試験後に総合得点や認定級を公表するのは構いませんが、どの問題が解けたかなどの情報は発信しないようにお願いします。
問題文
数列 A があり、A は初め空です。
A
, B
, C
, D
, E
, F
, L
, R
からなる長さ N の文字列 S が与えられます。
S の i 文字目を S_i と表すことにします。
i = 1, 2, 3, \dots, N のそれぞれについて、この順に以下の処理を行ってください。
- S_i が
L
のとき : A の先頭に i を挿入する。 - S_i が
R
のとき : A の末尾に i を挿入する。 - S_i が
A
のとき : A の長さが 0 以下ならERROR
と出力する。そうでなければ、A の前から 1 番目の数を出力し削除する。 - S_i が
B
のとき : A の長さが 1 以下ならERROR
と出力する。そうでなければ、A の前から 2 番目の数を出力し削除する。 - S_i が
C
のとき : A の長さが 2 以下ならERROR
と出力する。そうでなければ、A の前から 3 番目の数を出力し削除する。 - S_i が
D
のとき : A の長さが 0 以下ならERROR
と出力する。そうでなければ、A の後ろから 1 番目の数を出力し削除する。 - S_i が
E
のとき : A の長さが 1 以下ならERROR
と出力する。そうでなければ、A の後ろから 2 番目の数を出力し削除する。 - S_i が
F
のとき : A の長さが 2 以下ならERROR
と出力する。そうでなければ、A の後ろから 3 番目の数を出力し削除する。
制約
- 1 ≤ N ≤ 3 \times 10^5
- S は
A
,B
,C
,D
,E
,F
,L
,R
からなる長さ N の文字列
入力
入力は以下の形式で標準入力から与えられる。
N S
出力
問題文の指示に従って、改行区切りで出力せよ。
入力例 1
11 LLRLRCDEFBA
出力例 1
1 5 2 ERROR 3 4
以下のように処理されます。
- S_1 は
L
なので、1 を先頭に挿入する。A = (1) となる。 - S_2 は
L
なので、2 を先頭に挿入する。A = (2, 1) となる。 - S_3 は
R
なので、3 を末尾に挿入する。A = (2, 1, 3) となる。 - S_4 は
L
なので、4 を先頭に挿入する。A = (4, 2, 1, 3) となる。 - S_5 は
R
なので、5 を末尾に挿入する。A = (4, 2, 1, 3, 5) となる。 - S_6 は
C
なので、前から 3 番目の数 1 を出力し削除する。A = (4, 2, 3, 5) となる。 - S_7 は
D
なので、後ろから 1 番目の数 5 を出力し削除する。A = (4, 2, 3) となる。 - S_8 は
E
なので、後ろから 2 番目の数 2 を出力し削除する。A = (4, 3) となる。 - S_9 は
F
であるが、長さが 2 以下なので、ERROR
を出力する。 - S_{10} は
B
なので、前から 2 番目の数 3 を出力し削除する。A = (4) となる。 - S_{11} は
A
なので、前から 1 番目の数 4 を出力し削除する。A = () となる。
入力例 2
36 RLLDBBDDLCLDFRLRRLRRFLRDRLALLELCAARF
出力例 2
1 2 ERROR 3 ERROR ERROR 9 ERROR 17 23 26 20 28 31 29 19
Score : 7 points
Warning
Do not make any mention of this problem until April 24, 2021, 6:00 p.m. JST. In case of violation, compensation may be demanded. After the examination, you can reveal your total score and grade to others, but nothing more (for example, which problems you solved).
Problem Statement
We have a sequence A, which is initially empty.
You are given a string S of length N consisting of A
, B
, C
, D
, E
, F
, L
, and R
.
Let S_i denotes the i-th character of S.
For each i = 1, 2, 3, \dots, N in this order, do as follows:
- If S_i is
L
: insert i at the beginning of A. - If S_i is
R
: insert i at the end of A. - If S_i is
A
: if the length of A is less than 1, printERROR
; otherwise, print the first number from the beginning of A and delete it. - If S_i is
B
: if the length of A is less than 2, printERROR
; otherwise, print the second number from the beginning of A and delete it. - If S_i is
C
: if the length of A is less than 3, printERROR
; otherwise, print the third number from the beginning of A and delete it. - If S_i is
D
: if the length of A is less than 1, printERROR
; otherwise, print the first number from the end of A and delete it. - If S_i is
C
: if the length of A is less than 2, printERROR
; otherwise, print the second number from the end of A and delete it. - If S_i is
C
: if the length of A is less than 3, printERROR
; otherwise, print the third number from the end of A and delete it.
Constraints
- 1 ≤ N ≤ 3 \times 10^5
- S is a string of length N consisting of
A
,B
,C
,D
,E
,F
,L
, andR
.
Input
Input is given from Standard Input in the following format:
N S
Output
Print numbers as specified in Problem Statement, each in its own line.
Sample Input 1
11 LLRLRCDEFBA
Sample Output 1
1 5 2 ERROR 3 4
The process goes as follows:
- S_1 is
L
, so we insert 1 at the beginning. A = (1) now. - S_2 is
L
, so we insert 2 at the beginning. A = (2, 1) now. - S_3 is
R
, so we insert 3 at the end. A = (2, 1, 3) now. - S_4 is
L
, so we insert 4 at the beginning. A = (4, 2, 1, 3) now. - S_5 is
R
, so we insert 5 at the beginning. A = (4, 2, 1, 3, 5) now. - S_6 is
C
, so we delete the third number from the beginning: 1. A = (4, 2, 3, 5) now. - S_7 is
D
, so we delete the first number from the end: 5. A = (4, 2, 3) now. - S_8 is
E
, so we delete the second number from the end: 2. A = (4, 3) now. - S_9 is
F
, but we have less than 3 numbers, so we printERROR
. - S_{10} is
B
, so we delete the second number from the beginning: 3. A = (4) now. - S_{11} is
A
, so we delete the first number from the beginning: 4. A = () now.
Sample Input 2
36 RLLDBBDDLCLDFRLRRLRRFLRDRLALLELCAARF
Sample Output 2
1 2 ERROR 3 ERROR ERROR 9 ERROR 17 23 26 20 28 31 29 19