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 re | |
def solution(files): | |
# 1. | |
temp = [re.split(r"([0-9]+)", s) for s in files] | |
print(temp) | |
# 2. | |
sort = sorted(temp, key = lambda x: (x[0].lower(), int(x[1]))) | |
# 3. | |
return ["".join(s) for s in sort] |
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
test_case = int(input()) | |
def parent_find(x): | |
if x == parent[x]: | |
return x | |
else: | |
p = parent_find(parent[x]) | |
parent[x] = p | |
return parent[x] | |
# x가 y의 parent인 것으로 전제한다. |
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
n = int(input()) | |
arr = [] | |
for _ in range(n): | |
a, b = map(int, input().split()) | |
arr.append((a, b)) | |
# 가장 빨리 끝나는 회의 먼저 배정하고, 똑같은 시간에 끝나는 회의라면 먼저 시작하는 회의를 우선순위로 둔다. | |
arr = sorted(arr, key = lambda x: (x[1], x[0])) | |
count = 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 heapq | |
def solution(n, works): | |
if sum(works) < n: return 0 | |
works = [-i for i in works] | |
heapq.heapify(works) | |
while n > 0: | |
heapq.heappush(works, heapq.heappop(works) + 1) | |
n -= 1 | |
return sum([i**2 for i in works]) |
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(n, works): | |
if sum(works) < n: return 0 | |
works = [-i for i in works] | |
heapq.heapify(works) | |
while n > 0: | |
heapq.heappush(works, heapq.heappop(works) + 1) | |
n -= 1 | |
return sum([i**2 for i in works]) |
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 move(frm, to, mid, n, answer): | |
if n == 1: | |
# 시작지 -> 목적지를 answer에 리스트로 저장한다 | |
answer.append([frm, to]) | |
return | |
# 1. | |
move(frm, mid, to, n - 1, answer) | |
# 2. | |
answer.append([frm, to]) |
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
from collections import deque | |
import sys | |
t = int(sys.stdin.readline()) | |
dirs = [(1,0), (-1,0), (0,1), (0,-1)] | |
def bfs(start, maps): | |
queue = deque() | |
queue.append(start) | |
while queue: | |
y, x = queue.popleft() |
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
from collections import deque | |
start, des = map(int, input().split()) | |
# 중복 방지를 위해, 수빈이가 도착하는 위치를 저장한다. | |
visited = set() | |
def bfs(start, end, visited): | |
queue = deque() | |
# 시작 지점 | |
queue.append((start,0)) | |
visited.add(start) |
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
from collections import deque | |
def bfs(start, image, visited): | |
queue = deque() | |
queue.append(start) | |
# 탐색에 사용할 색상 번호. | |
color = image[start[0]][start[1]] | |
dirs = [(0,1),(0,-1),(1,0),(-1,0)] | |
while queue: | |
y, x = queue.popleft() |
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 re | |
from collections import Counter | |
def solution(str1, str2): | |
# 소문자 2개씩만 추출하는 정규식 표현 | |
regex = re.compile('[a-z][a-z]') | |
# 대소문자 구분을 없애기 위해 전부 소문자로 변환 | |
str1, str2 = str1.lower(), str2.lower() | |
# 문자열 2개씩 묶은 데이터형으로 변환. | |
str1_ = regex.findall(" ".join(str1[i:i+2] for i in range(0, len(str1)))) |