This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
def solution(food_times, k): | |
# (음식 크기, 원판에서의 위치) 로 food_times 재정의 | |
food_times = [(food, idx) for idx, food in enumerate(food_times, 1)] | |
# heapify. 음식 크기가 작은 순으로 뽑아낸다. | |
heapq.heapify(food_times) | |
# 가장 크기 작은 음식 | |
small_food = food_times[0][0] | |
prev_food = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(cacheSize, cities): | |
# 캐시 사이즈가 0이면, 모든 input이 전부 cache miss다. | |
if cacheSize == 0: | |
return len(cities) * 5 | |
cache = [] | |
runtime = 0 | |
for city in cities: | |
city = city.lower() | |
# cache에 존재하지 않는 경우 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from collections import deque | |
import heapq | |
n = int(sys.stdin.readline()) | |
maps = [] | |
for y in range(n): | |
arr = list(map(int, sys.stdin.readline().split())) | |
for x in range(len(arr)): | |
if arr[x] == 9: | |
start = (y, x, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# UTF-8 encoding when using korean | |
from collections import deque | |
M, N = map(int, input().split()) | |
maps = [] | |
start = [] | |
for y in range(N): | |
temp = list(map(int, input().split())) | |
for x in range(M): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# UTF-8 encoding when using korean | |
import sys | |
import heapq | |
from collections import defaultdict | |
n = int(sys.stdin.readline()) | |
work_list = [list(map(int,sys.stdin.readline().replace("\n","").split())) for _ in range(n)] | |
# 날짜 순 오름차순 정렬 | |
# ex) 현재가 7일이면, 마감일이 6일 이전인 일들을 작업할 수 없다. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# UTF-8 encoding when using korean | |
import sys | |
N = int(sys.stdin.readline()) | |
M = int(sys.stdin.readline()) | |
arr = [0 for _ in range(N+1)] | |
for _ in range(M): | |
idx = int(sys.stdin.readline()) | |
arr[idx] = 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import heapq | |
from collections import defaultdict | |
def solve(precede_list, build_next, time, target): | |
# 조건 없이 바로 만들 수 있는 건물들 찾기 | |
queue = [(time[idx], idx) for idx in range(1, len(precede_list)) if precede_list[idx] == 0] | |
# 시간순서로 정렬. 가장 시간 짧은 것부터 뽑아내는 min heap 사용 | |
heapq.heapify(queue) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
import sys | |
# 중앙값 기준으로 작은 값 = left, 큰 값 = right | |
left, right = [], [] | |
n = int(sys.stdin.readline()) | |
for _ in range(n): | |
num = int(sys.stdin.readline()) | |
if len(left) == len(right): | |
# max_heap. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
# Complete the climbingLeaderboard function below. | |
def climbingLeaderboard(scores, alice): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
from collections import Counter | |
# Complete the isValid function below. |