참고블로그 : https://handhand.tistory.com/178
import sys
N, K, D = list(map(int, sys.stdin.readline().split()))
rules = [list(map(int, sys.stdin.readline().split())) for _ in range(K)]
def dotori(pivot):
total = 0
for start, end, step in rules:
beta = min(end, pivot)
if start <= beta:
calc = (beta - start) // step + 1
total += calc
return total
def sol():
lo, hi = 1, 1000000
ans = 0
while lo <= hi:
mid = (lo + hi) // 2
if dotori(mid) >= D:
ans = mid
hi = mid - 1
else:
lo = mid + 1
return ans
print(sol())
https://ariz1623.tistory.com/274
import bisect
import collections
def func(a,left,right):
left_idx = bisect.bisect_left(a,left)
right_idx = bisect.bisect_right(a,right)
return right_idx - left_idx
def solution(words, queries):
answer = []
# 단어 길이 순 딕셔너리 생성
dic = collections.defaultdict(list)
dic_reverse = collections.defaultdict(list)
for word in words:
dic[len(word)].append(word)
dic_reverse[len(word)].append(word[::-1])
#정렬
for key in dic.keys():
dic[key].sort()
dic_reverse[key].sort()
for query in queries:
#접미사에 와일드 카드
if query[0] != '?':
answer.append(func(dic[len(query)],query.replace('?','a'),query.replace('?','z')))
#접두사에 와일드 카드
else :
query = query[::-1]
answer.append(func(dic_reverse[len(query)],query.replace('?','a'),query.replace('?','z')))
return answer
도토리 키재기 문제 저도 잘 이해가 안가요😂 이번주 정말 고생 많으셨습니다👍👍 다음주도 같이 열심히 해요!!