메모리: 223272 KB, 시간: 2508 ms
덱, 파싱, 구현, 문자열, 자료 구조
T=int(input())
for _ in range(T):
flag=False
P=list(input())
n=int(input())
lst=input()[1:-1]
if len(lst):
lst=list(map(int,lst.split(',')))
odd=0
start,end=0,n
for p in P:
if p=='R':
odd+=1
elif p=='D':
# 에러가 발생한 경우
if end<=start:
print("error")
flag=True
break
# 그 외
if odd%2==0: # 짝수라면
start+=1
else: # 홀수라면
end-=1
if not flag:
ans='['
if odd%2==0:
s,e,k=start,end,1
else:
s,e,k=end-1,start-1,-1
for i in range(s,e,k):
ans+=str(lst[i])
if (odd%2==1 and i!=e+1) or (odd%2==0 and i!=e-1):
ans+=','
ans+=']'
print(ans)
계속 틀렸던 이유
1. 단순 print(list)로 리스트 출력 시 원소들 사이에 불필요한 공백이 출력 → 공백 없이 출력해야함.
2.요소가 없을 때는 빈 리스트로 "[]"로 출력해야함
3.시간초과 이슈
https://www.acmicpc.net/board/view/25456

처음 문제를 읽고 골드5인데 너무 쉬운 문제 아닌가? 했는데 풀다보니 은근 문자열처리가 까다로워서 계속 틀렸다..
'coding test > Baekjoon' 카테고리의 다른 글
| [Python] 23796번. 2,147,483,648 게임 (1) | 2026.01.06 |
|---|---|
| [Python] 13460번. 구슬 탈출 2 (0) | 2026.01.02 |
| [Python] 11438번 LCA 2 (0) | 2025.12.15 |
| [Python] 3584번 가장 가까운 공통 조상 (0) | 2025.12.13 |
| [Python] 11437번 LCA (0) | 2025.12.12 |
