반응형
12739번: 돌림판 (Small) (acmicpc.net)
"""12739번 돌림판(small)"""
from sys import stdin
N, K = map(int, stdin.readline().strip("\n").split(" "))
STR = stdin.readline().strip("\n")
ANSWER_COLOR = {"R": 0, "G": 0, "B": 0}
for _ in range(0, K):
NEW_STR = ""
for i in range(0, N):
PL = STR[((i - 1) + N) % N]
P = STR[i]
PR = STR[(i + 1) % N]
COLOR = {"R": 0, "G": 0, "B": 0}
COLOR[PL] += 1
COLOR[P] += 1
COLOR[PR] += 1
if PL == P == PR:
NEW_STR += "B"
elif PL != P and P != PR and PL != PR:
NEW_STR += "B"
elif (
(COLOR["R"] == 2 and COLOR["G"] == 1)
or (COLOR["G"] == 2 and COLOR["B"] == 1)
or (COLOR["B"] == 2 and COLOR["R"] == 1)
):
NEW_STR += "R"
else:
NEW_STR += "G"
STR = NEW_STR
for i, value in enumerate(STR):
ANSWER_COLOR[value] += 1
print(ANSWER_COLOR["R"], ANSWER_COLOR["G"], ANSWER_COLOR["B"])
반응형
'알고리즘' 카테고리의 다른 글
25329번 학생별 통화 요금 계산 (0) | 2024.05.19 |
---|---|
1384번 메시지 (0) | 2024.05.07 |
17091번 단어 시계 (0) | 2024.05.06 |
14468번 소가 길을 건너간 이유2 (0) | 2024.05.05 |
1213번 팰린드롬 만들기 (0) | 2023.07.07 |