From 56d4824a8ce64528c995e4acceec0621a0cce973 Mon Sep 17 00:00:00 2001 From: timo Date: Sun, 9 Oct 2022 19:15:21 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[kakao]=20=EC=99=84=EC=A0=84=ED=83=90?= =?UTF-8?q?=EC=83=89=EC=9D=84=20=EC=9D=B4=EC=9A=A9=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 중요한 점은 메뉴의 리스트를 모아서 사용하면 n이 최대 24가 될 수 있어 시간초과가 남 - 메뉴의 형식으로 완전 탐색을 사용하면 10이 됨 related to #8 --- kakao_2021_blind/menu_renewal.py | 54 ++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 kakao_2021_blind/menu_renewal.py diff --git a/kakao_2021_blind/menu_renewal.py b/kakao_2021_blind/menu_renewal.py new file mode 100644 index 0000000..57bc28e --- /dev/null +++ b/kakao_2021_blind/menu_renewal.py @@ -0,0 +1,54 @@ +from collections import Counter +from collections import defaultdict + +import itertools + +def solution(orders, course): + answer = [] + cand_comb_menu = [] + + for num in course: + for order in orders: + comb_menues = list(itertools.combinations(order, num)) + + #AC, AD, AE + for comb_menu in comb_menues: + comb_menu = sorted(comb_menu) + cand_comb_menu.append("".join(comb_menu)) + + cand_comb_menu = Counter(cand_comb_menu).most_common() + + best_like_dict = defaultdict(int) + + for course_num in course: + best_like = 0 + + for menu, like in cand_comb_menu: + if len(menu) == course_num: + best_like = max(best_like, like) + + best_like_dict[course_num] = best_like + + + for course_num in course: + if best_like_dict[course_num] == 0 or best_like_dict[course_num] < 2: + continue + + for menu, like in cand_comb_menu: + if len(menu) == course_num and like == best_like_dict[course_num]: + answer.append(menu) + + print(sorted(answer)) + return answer + + +if __name__ == "__main__": + orders = ["ABCDE", "AB", "CD", "ADE", "XYZ", "XYZ", "ACD"] + course = [2,3,5] + + solution(orders, course) + + + + + \ No newline at end of file From 713019b0828f24f0157ad0c2c0d2c7e697986d67 Mon Sep 17 00:00:00 2001 From: timo Date: Mon, 31 Oct 2022 00:20:58 +0900 Subject: [PATCH 2/4] [brute_force] Make query_set MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 주어진 info 목록을 가지고 적절한 쿼리셋을 만들 수 있어야 함 - 정렬된 리스트에서 빠르게 타겟 값을 검색할 수 있는지 related to #8 --- kakao_2021_blind/searching_ranking.py | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 kakao_2021_blind/searching_ranking.py diff --git a/kakao_2021_blind/searching_ranking.py b/kakao_2021_blind/searching_ranking.py new file mode 100644 index 0000000..64d9b6f --- /dev/null +++ b/kakao_2021_blind/searching_ranking.py @@ -0,0 +1,59 @@ +import bisect +from copy import deepcopy +from itertools import combinations + + +def make_sub_query(info): + keys = [] + keys.append(" ".join(info)) + for k in range(1, 5): + for sub in list(combinations(range(0, 4), k)): + case = deepcopy(info) + + for idx in sub: + case[idx] = '-' + + keys.append(" ".join(case)) + return keys + + +def solution(infos, querys): + + info_dict = {} + + for info in infos: + lang, ground, pos, food, score = info.split() + query_set = make_sub_query([lang, ground, pos, food]) + + for q in query_set: + if q in info_dict.keys(): + info_dict[q].append(int(score)) + else: + info_dict[q] = [int(score)] + + for key in info_dict.keys(): + info_dict[key].sort() + + answer = [] + + for q in querys: + q = q.replace(" and", "") + lang, ground, pos, food, score = q.split() + + query_of_key = " ".join([lang, ground, pos, food]) + + if query_of_key in info_dict.keys(): + score_list = info_dict[query_of_key] + answer.append(len(score_list) - bisect.bisect_left(score_list, int(score))) + + else: + print("Asd") + answer.append(0) + + return answer + + +if __name__ == "__main__": + info = ["java backend junior pizza 150","python frontend senior chicken 210","python frontend senior chicken 150","cpp backend senior pizza 260","java backend junior chicken 80","python backend senior chicken 50"] + query = ["java and backend and junior and pizza 100","python and frontend and senior and chicken 200","cpp and - and senior and pizza 250","- and backend and senior and - 150","- and - and - and chicken 100","- and - and - and - 150"] + print(solution(info, query)) \ No newline at end of file From 4016937e599483bd9a9f19bdf965ac1f994cb329 Mon Sep 17 00:00:00 2001 From: timo Date: Sun, 6 Nov 2022 13:46:16 +0900 Subject: [PATCH 3/4] [kakao] Using psum - version1 --- kakao_2021_blind/advertise_inserting.py | 67 +++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 kakao_2021_blind/advertise_inserting.py diff --git a/kakao_2021_blind/advertise_inserting.py b/kakao_2021_blind/advertise_inserting.py new file mode 100644 index 0000000..a9487de --- /dev/null +++ b/kakao_2021_blind/advertise_inserting.py @@ -0,0 +1,67 @@ +def chagne_time_to_sec(time): + h, m, s = map(int, time.split(":")) + + return h * 3600 + m * 60 + s + +def change_sec_to_time(sec): + m, s = divmod(sec, 60) + h, m = divmod(m, 60) + + h, m, s = map(str, [h,m,s]) + + h = h.zfill(2) + m = m.zfill(2) + s = s.zfill(2) + + time = ":".join([h,m,s]) + return time + + + +def sum_watching_player(psum_of_time, logs): + + for log in logs: + start_time, end_time = map(chagne_time_to_sec, log.split("-")) + + for i in range(start_time, end_time): + psum_of_time[i] = psum_of_time[i] + 1 + +def solution(play_time, adv_time, logs): + answer = '' + + play_time_sec = chagne_time_to_sec(play_time) + psum_of_time = [0] * (play_time_sec + 1) + + adv_time_sec = chagne_time_to_sec(adv_time) + + sum_watching_player(psum_of_time, logs) + + max_watching_time = 0 + watching_time = 0 + start_time_sec = 0 + + for i in range(1, adv_time_sec): + max_watching_time += psum_of_time[i-1] + + watching_time = max_watching_time + + for i in range(adv_time_sec, len(psum_of_time)): + watching_time = watching_time + psum_of_time[i - 1] - psum_of_time[i - adv_time_sec - 1] + + if max_watching_time < watching_time: + max_watching_time = watching_time + start_time_sec = i - adv_time_sec + + start_time = change_sec_to_time(start_time_sec) + + return start_time + + + + +if __name__ == "__main__": + play_time = "99:59:59" + adv_time = "25:00:00" + logs = ["69:59:59-89:59:59", "01:00:00-21:00:00", "79:59:59-99:59:59", "11:00:00-31:00:00"] + + print(solution(play_time, adv_time, logs)) From 973aa53636f78b2a9bad9e736953e5d30f80cc23 Mon Sep 17 00:00:00 2001 From: timo Date: Mon, 7 Nov 2022 01:14:46 +0900 Subject: [PATCH 4/4] [kakao] Using psum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 시간을 초로 변경 후 누적합을 사용하는 문제 related to #9 --- kakao_2021_blind/advertise_inserting.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kakao_2021_blind/advertise_inserting.py b/kakao_2021_blind/advertise_inserting.py index a9487de..6fe34ed 100644 --- a/kakao_2021_blind/advertise_inserting.py +++ b/kakao_2021_blind/advertise_inserting.py @@ -23,8 +23,12 @@ def sum_watching_player(psum_of_time, logs): for log in logs: start_time, end_time = map(chagne_time_to_sec, log.split("-")) - for i in range(start_time, end_time): - psum_of_time[i] = psum_of_time[i] + 1 + psum_of_time[start_time] = psum_of_time[start_time] + 1 + psum_of_time[end_time] = psum_of_time[end_time] -1 + + + for i in range(1, len(psum_of_time)): + psum_of_time[i] = psum_of_time[i] + psum_of_time[i - 1] def solution(play_time, adv_time, logs): answer = ''