목록코딩테스트/2020 KAKAO BLIND RECRUITMENT (7)
JH 개발 블로그
from collections import deque def rotate(lr, lc, rr, rc, board): locs = [] for dr, dc in ((-1, 0), (0, 1), (1, 0), (0, -1)): nlr, nlc, nrr, nrc = lr + dr, lc + dc, rr + dr, rc + dc if board[nlr][nlc] == 1 or board[nrr][nrc] == 1: continue locs.append((nlr, nlc, nrr, nrc)) if lr == rr: if lc < rc: if board[lr - 1][lc + 1] == 0 and board[lr - 1][lc] == 0: # 반시계 locs.append((lr, lc, lr - 1, lc)) if..
1. 순열을 이용하여 완전탐색 from itertools import permutations from bisect import bisect_right def solution(n, weak, dist): l = len(weak) weak_line = weak + [w+n for w in weak] answer = [] for friends in permutations(dist): for i in range(l): cnt = 0 position = weak[i] for friend in friends: cnt += 1 position += friend if position < weak_line[i+l-1]: position = weak_line[bisect_right(weak_line,position)] e..
def impossible(answer): for x,y,a in answer: if a == 0: if (x,y-1,0) in answer or (x-1,y,1) in answer or (x,y,1) in answer or y == 0: continue else: return True else: if (x,y-1,0) in answer or (x+1,y-1,0) in answer or ((x-1,y,1) in answer and (x+1,y,1) in answer): continue else: return True return False def solution(n, build_frame): answer = set() for x,y,a,b in build_frame: item = (x,y,a) if b:..
1. 정렬 후 이분탐색 ex) [probb ,proaa, prozz,procc]는 정렬 후 [proaa,probb,procc,prozz]가 된다. probb,procc는 proaa와 prozz 사이에 있음에 착안해서, ?를 a와 z로 바꾼후 그 사이에 있는 단어의 개수를 센다. from collections import defaultdict import bisect def find_result(word,left,right): left_idx = bisect.bisect_left(word,left) right_idx = bisect.bisect_right(word,right) return right_idx-left_idx def solution(words, queries): answer = [] word_..
def solution(key, lock): n,m = len(lock),len(key) new_map = [[0]*(2*(m-1)+n) for _ in range(2*(m-1)+n)] for i in range(n): for j in range(n): new_map[m-1+i][m-1+j] = lock[i][j] for _ in range(4): for i in range(m-1+n): for j in range(m-1+n): for k in range(m): for l in range(m): new_map[i+k][j+l] += key[k][l] flag = True for k in range(n): for l in range(n): if new_map[m-1+k][m-1+l] != 1: flag =..
def make_u_v(s): cnt1 = cnt2 = 0 for i in s: if i == '(': cnt1 += 1 else: cnt2 += 1 if cnt1 == cnt2: break return s[:cnt1 + cnt2], s[cnt1 + cnt2:] def is_right(s): cnt1 = cnt2 = 0 for i in s: if i == '(': cnt1 += 1 else: cnt2 += 1 if cnt2 > cnt1: return False return True def solution(p): if p == '': return p answer = '' u, v = make_u_v(p) if is_right(u): answer += u answer += solution(v) else: a..
def solution(s): answer = len(s) for step in range(1,len(s)//2+1): temp = [s[i:i+step] for i in range(0,len(s),step)] ans = 0 cnt = 0 for i in range(len(temp)-1): cnt += 1 if temp[i] == temp[i+1]: continue else: ans += len(temp[i]) + (len(str(cnt)) if cnt > 1 else 0) cnt = 0 cnt += 1 ans += len(temp[-1]) + (len(str(cnt)) if cnt > 1 else 0) answer = min(answer,ans) return answer