Skip to content

[BOJ-2065] 나룻배 - #56

Open
eddie-liner wants to merge 1 commit into
tae2089:mainfrom
eddie-liner:main
Open

[BOJ-2065] 나룻배#56
eddie-liner wants to merge 1 commit into
tae2089:mainfrom
eddie-liner:main

Conversation

@eddie-liner

@eddie-linereddie-liner commented Nov 3, 2022

Copy link
Copy Markdown
Collaborator

Signed-off-by: Kimyungi gozj3319@agape.hanyang.ac.kr

Coding Test Study Pull Request


문제 정보

문제 링크

문제 관련 알고리즘 or 자료구조

  • 큐, 시뮬레이션

해결 과정

작성 코드

importsysfromqueueimportdequeinput=sys.stdin.readlineif__name__=='__main__':
m, t, n=map(int, input().strip().split())
time=0curr='left'left_q=deque()
right_q=deque()
foriinrange(n):
arrive_time, location=input().strip().split()
iflocation=='left':
left_q.append((int(arrive_time), i))
else:
right_q.append((int(arrive_time), i))
answer= [0] * (len(left_q) +len(right_q))
whileleft_qorright_q:
cnt=0ifcurr=='left':
ifleft_q:
left=left_q[0][0]
else:
left=100001ifright_q:
right=right_q[0][0]
else:
right=100001ifleft<=timeorleft<=right: # left starttime=max(time, left)
whileleft_qandleft_q[0][0] <=timeandcnt<m:
_, idx=left_q.popleft()
cnt+=1answer[idx] =time+ttime+=tcurr='right'else: # right starttime=max(time, right) +twhileright_qandright_q[0][0] <=timeandcnt<m:
_, idx=right_q.popleft()
cnt+=1answer[idx] =time+ttime+=telse:
ifleft_q:
left=left_q[0][0]
else:
left=100001ifright_q:
right=right_q[0][0]
else:
right=100001ifright<=timeorright<=left: # right starttime=max(time, right)
whileright_qandright_q[0][0] <=timeandcnt<m:
_, idx=right_q.popleft()
cnt+=1answer[idx] =time+ttime+=tcurr='left'else: # left starttime=max(time, left) +twhileleft_qandleft_q[0][0] <=timeandcnt<m:
_, idx=left_q.popleft()
cnt+=1answer[idx] =time+ttime+=tforiinanswer:
print(i)

어려웠던 점

  • 큐를 두 개 사용해야 한다는 점과 입력받은 순서대로 출력해야 한다는 점을 모두 고려하는 것이 어려웠어여..

궁금한 점

  • 없음

기타

  • 값을 비교해서 확인해야 할 땐, popleft을 쓰는 것보다 indexing을 통해 값을 할당하는 것이 자잘한 에러 없이 코드를 짤 수 있네요..!

Signed-off-by: Kimyungi <gozj3319@agape.hanyang.ac.kr>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

백준백준

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@eddie-liner