ps | |
---|---|
링크 | programmers.co.kr/… |
출처 | 프로그래머스 |
문제 번호 | 72412 |
문제명 | 순위 검색 |
레벨 | Level 2 |
분류 |
구현, 이진검색 |
시간복잡도 | O((n+q)logn) |
인풋사이즈 | n<=50000, q<=100000 |
사용한 언어 | Python |
해결날짜 | 2021/01/26 |
출처 |
ps:problems:programmers:2021_kakao_blind_recruitment |
"""Solution code for "Programmers 72412. 순위 검색".
- Problem link: https://programmers.co.kr/learn/courses/30/lessons/72412
- Solution link: http://www.teferi.net/ps/problems/programmers/72412
"""
import bisect
import collections
def solution(info, query):
scores_by_type = collections.defaultdict(list)
for resume in info:
*types, score = resume.split()
scores_by_type[tuple(types)].append(int(score))
for scores in scores_by_type.values():
scores.sort()
answer = []
for q in query:
q_list = q.split()
type_filter = q_list[::2]
score_filter = int(q_list[-1])
count = sum(
len(scores) - bisect.bisect_left(scores, score_filter)
for types, scores in scores_by_type.items()
if all(f in ['-', t] for f, t in zip(type_filter, types)))
answer.append(count)
return answer