Skip to content

Instantly share code, notes, and snippets.

View inspirit941's full-sized avatar

Donggeon Lee inspirit941

View GitHub Profile
def rotate(maps):
return [list(reversed(i)) for i in zip(*maps)]
def solution(key, lock):
hole = 0
for y in range(len(lock)):
for x in range(len(lock[0])):
if lock[y][x] == 0:
hole += 1
from copy import deepcopy
import re
# 해당 조합의 중복여부를 확인하기 위한 리스트
check = []
def dfs_check(idx, candidates, arr, length):
global answer, check
# 조합 끝까지 전부 확인한 경우
if idx == len(candidates):
# banned_id 길이와 일치하고, 중복된 조합이 아닐 경우
import sys
sys.setrecursionlimit(1500)
# 방을 찾는 함수
def find_empty_room(x, rooms):
# 현재 방넘버 x에 아무도 배정되지 않은 경우
if x not in rooms:
# 현재 방넘버 기준, 다음으로 빈 방 좌표를 저장한다.
rooms[x] = x + 1
# 현재 방넘버 x를 반환한다.
return x
def solution(s):
s = s[2:-2].split("},{")
sorted_s = sorted(s, key = lambda x: len(x))
answer = []
check = set()
for value in sorted_s:
for each_value in value.split(","):
if each_value not in check:
answer.append(int(each_value))
check.add(each_value)
# 인형이 있는지 탐색하는 함수
def get_doll(idx, board):
for i in range(len(board[idx-1])):
# 해당 인형이 있으면, 인형의 위치 값을 0으로 수정하고
# 그 인형의 값을 리턴한다.
if board[idx-1][i] != 0:
value = board[idx-1][i]
board[idx-1][i] = 0
return value
from collections import deque
N, M = map(int, input().split())
dirs = [(1,0), (-1,0), (0,1), (0,-1)]
dist = [[0 for _ in range(M)] for _ in range(N)]
maps = [list(map(int, list(input()))) for _ in range(N)]
queue = deque()
queue.append((0,0))
dist[0][0] = 1
while queue:
cur_y, cur_x = queue.popleft()
from itertools import combinations
import sys
L, C = map(int, sys.stdin.readline().split())
arr = sys.stdin.readline().split()
arr.sort()
vowel = {'a','e','i','o','u'}
consonant = set(list("abcdefghijklmnopqrstuvwxyz")) - vowel
candidate = combinations(range(len(arr)), L)
for value in candidate:
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
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에 존재하지 않는 경우
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)