[BOJ] 1713 후보 추천하기

BbickBbick_Develop·2022년 12월 15일
0

BOJ

목록 보기
8/8
post-thumbnail

풀이

N = int(input())
M = int(input())
recommend = list(map(int, input().split()))

slot = dict()
cnt = 0
for rec in recommend:
	# 슬롯이 꽉 차있는 상태에서 교체해야 하는 경우
    if len(slot) >= N and not rec in slot:
    	# 가장 갯수가 적은 것을 삭제함
        del slot[min(slot, key=lambda x:slot[x])]
    # 이미 있는 거면 추천 수를 하나씩 추가함
    try: slot[rec][0] += 1
    # 새로 추가했다면 카운트를 하나씩 추가함
    except:
        slot[rec] = [1, cnt]
        cnt += 1
print(*sorted(slot.keys()))

감상

아직 제대로 해시를 잘 사용하지 못하는 것 같다.

profile
삑삑도요가 되자

0개의 댓글