반응형
from itertools import combinations
from collections import defaultdict
import bisect
def solution(info, query):
answer = []
people = defaultdict(list)
for i in info:
person = i.split()
score = int(person[-1])
people[''.join(person[:-1])].append(score)
for j in range(4):
candi = list(combinations(person[:-1], j))
for c in candi:
people[''.join(c)].append(score)
for i in people:
people[i].sort() # 이진 탐색을 사용하기 위한 정렬
for i in query:
key = i.split()
score = int(key.pop())
key = ''.join(key)
key = key.replace('and', '').replace(' ', '').replace('-', '')
answer.append(len(people[key])-bisect.bisect_left(people[key], score))
return
반응형
'알고리즘' 카테고리의 다른 글
[파이썬🐍] 프로그래머스 : 택배상자 (0) | 2023.02.06 |
---|---|
[파이썬🐍] 프로그래머스 : 혼자 놀기의 달인 (0) | 2023.01.11 |
[파이썬🐍] 프로그래머스 : 부대복귀 (0) | 2023.01.11 |
[파이썬🐍] 프로그래머스 : 롤케이크 자르기 (0) | 2023.01.10 |
[파이썬🐍] 프로그래머스 : 다단계 칫솔 판매 (0) | 2023.01.10 |
댓글