Submission #22212522


Source Code Expand

s = input()
n = len(s)
t_head = ['']*n
t_tail = ['']*n
head = 1
head_ind = 0
tail_ind = 0
for i in range(n):
    if s[i] == 'R':
        head *= -1
    else:
        if head == 1:
            if head_ind > 0 and t_head[head_ind-1] == s[i]:
                t_head[head_ind-1] = ''
                head_ind -= 1
            else:
                t_head[head_ind] = s[i]
                head_ind += 1
        else:
            if tail_ind > 0 and t_tail[tail_ind-1] == s[i]:
                t_tail[tail_ind-1] = ''
                tail_ind -= 1
            else:
                t_tail[tail_ind] = s[i]
                tail_ind += 1

for i in range(min(len(t_head), len(t_tail))):
    if t_head[i] == t_tail[i]:
        t_tail[i] = ''
        t_head[i] = ''
    else:
        break
ret = ''
ret_head = ''  
ret_tail = ''
if head == 1:
    t_tail.reverse()
    for st in t_head:
        ret_head += st
    for st in t_tail:
        ret_tail += st
    ret = ret_tail + ret_head
else:
    t_head.reverse()
    for st in t_head:
        ret_head += st
    for st in t_tail:
        ret_tail += st
    ret = ret_head + ret_tail
print(ret)

Submission Info

Submission Time
Task D - Message from Aliens
User Arcamon
Language Python (3.8.2)
Score 300
Code Size 1179 Byte
Status AC
Exec Time 338 ms
Memory 17804 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 28
Set Name Test Cases
Sample 01_sample.txt, 02_sample.txt
All 01_sample.txt, 02_sample.txt, 03_random.txt, 04_random.txt, 05_random.txt, 06_random.txt, 07_random.txt, 08_random.txt, 09_random.txt, 10_random.txt, 11_random.txt, 12_random.txt, 13_random.txt, 14_random.txt, 15_random.txt, 16_random.txt, 17_random.txt, 18_random.txt, 19_random.txt, 20_random.txt, 21_random.txt, 22_random.txt, 23_max.txt, 24_max.txt, 25_max.txt, 26_max.txt, 27_max.txt, 28_max.txt
Case Name Status Exec Time Memory
01_sample.txt AC 18 ms 9200 KiB
02_sample.txt AC 17 ms 9100 KiB
03_random.txt AC 23 ms 8972 KiB
04_random.txt AC 18 ms 8968 KiB
05_random.txt AC 29 ms 8948 KiB
06_random.txt AC 138 ms 12824 KiB
07_random.txt AC 62 ms 10452 KiB
08_random.txt AC 19 ms 8856 KiB
09_random.txt AC 88 ms 10796 KiB
10_random.txt AC 63 ms 10180 KiB
11_random.txt AC 22 ms 8856 KiB
12_random.txt AC 19 ms 9012 KiB
13_random.txt AC 23 ms 9264 KiB
14_random.txt AC 24 ms 8972 KiB
15_random.txt AC 44 ms 9400 KiB
16_random.txt AC 18 ms 8856 KiB
17_random.txt AC 22 ms 8872 KiB
18_random.txt AC 34 ms 9228 KiB
19_random.txt AC 24 ms 9072 KiB
20_random.txt AC 28 ms 9116 KiB
21_random.txt AC 41 ms 9700 KiB
22_random.txt AC 18 ms 9100 KiB
23_max.txt AC 241 ms 17104 KiB
24_max.txt AC 306 ms 17104 KiB
25_max.txt AC 295 ms 17804 KiB
26_max.txt AC 269 ms 17008 KiB
27_max.txt AC 251 ms 17664 KiB
28_max.txt AC 338 ms 17132 KiB