백준 27325번: 3 つの箱 (Three Boxes) #Python

ColorlessDia·2024년 5월 13일

algorithm/baekjoon

목록 보기
175/808
N = int(input())
S = input()

box_list = [0, 1, 0, 0]

ball = box_list.index(1)
count = 0

for char in S:
    if char == 'L' and ball != 1:
        box_list[ball] = 0
        box_list[ball - 1] = 1
        ball -= 1
    elif char == 'R' and ball != 3:
        box_list[ball] = 0
        box_list[ball + 1] = 1
        ball += 1
    
    if ball == 3:
        count += 1

print(count)

0개의 댓글