Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions wnsmir/ํ•ด์‹œ/์ˆœ์œ„ ๊ฒ€์ƒ‰.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from collections import defaultdict
from itertools import combinations
from bisect import bisect_left

def solution(info, query):
# ์ „์ฒ˜๋ฆฌ: 16๊ฐœ ํ‚ค์— ์ ์ˆ˜ ์ ์žฌ
db = defaultdict(list)
for s in info:
lang, job, career, food, score = s.split()
score = int(score)
fields = [lang, job, career, food]

# 4๊ฐœ์˜ ํ•„๋“œ์—์„œ 0~4๊ฐœ๋ฅผ '-'๋กœ ์น˜ํ™˜ํ•œ ๋ชจ๋“  ์กฐํ•ฉ(2^4=16)
for r in range(5):
for idxs in combinations(range(4), r):
key = fields[:] # ๋ณต์‚ฌ
for i in idxs:
key[i] = '-'
db[tuple(key)].append(score)
Comment on lines +13 to +19
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

16๊ฐœ ์กฐํ•ฉ์„ ๋งŒ๋“œ๋Š” ๋ถ€๋ถ„์ด ์˜ˆ์ˆ ์ด๋„ค์š”.
์ €๋Š” 16๊ฐœ ํ•˜๋“œ์ฝ”๋”ฉ ํ–ˆ์Šต๋‹ˆ๋‹ค.
๋ชธ์ด ์กฐ๊ธˆ ๊ณ ์ƒํ•œ๋‹ค๋Š” ๋งˆ์ธ๋“œ..;;


# ๊ฐ ํ‚ค์˜ ์ ์ˆ˜ ๋ฆฌ์ŠคํŠธ ์ •๋ ฌ(์ด๋ถ„ ํƒ์ƒ‰)
for k in db:
db[k].sort()

# ์ฟผ๋ฆฌ ์ฒ˜๋ฆฌ: ํ‚ค ๋งŒ๋“ค๊ณ , lower_bound๋กœ ๊ฐœ์ˆ˜ ๊ณ„์‚ฐ
answer = []
for que in query:
# "java and backend and junior and pizza 100" -> ["java","backend","junior","pizza","100"]
que = que.replace(" and ", " ")
a, b, c, d, min_score = que.split()
key = (a, b, c, d)
scores = db.get(key, [])
# ์ ์ˆ˜ >= min_score ์ธ ์›์†Œ ๊ฐœ์ˆ˜ = ์ „์ฒด - ์ฒซ ์œ„์น˜
idx = bisect_left(scores, int(min_score))
answer.append(len(scores) - idx)

return answer