-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkakao_3_dooyeong.py
More file actions
46 lines (33 loc) · 1023 Bytes
/
kakao_3_dooyeong.py
File metadata and controls
46 lines (33 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from itertools import combinations as cbi
def solution(info, query):
def bin_search(li, target):
st, en = 0, len(li)-1
while st <= en:
m = (st+en)//2
if li[m] >= target:
en = m - 1
else:
st = m + 1
return en + 1
ans = []
infoDic = dict()
for i in info:
tmpI = i.split(' ')
tmpScore = tmpI.pop()
for cnt in range(5):
for c in cbi(tmpI, cnt):
if c not in infoDic:
infoDic[c] = []
infoDic[c].append(int(tmpScore))
for key in infoDic:
infoDic[key].sort()
for q in query:
tmpQ = [word for word in q.split(' ') if word != 'and' and word != '-']
tmpScore = int(tmpQ.pop())
tmpQ = tuple(tmpQ)
if tmpQ not in infoDic:
ans.append(0)
continue
idx = bin_search(infoDic[tmpQ], tmpScore)
ans.append(len(infoDic[tmpQ]) - idx)
return ans