목록코딩테스트/2022 KAKAO BLIND RECRUITMENT (7)
JH 개발 블로그
dir = ((-1,0),(0,1),(1,0),(0,-1)) def A_turn(ar,ac,br,bc,cnt,board): if board[ar][ac] == 0: return (1,cnt) winner = [] loser = [] flag = False for dr,dc in dir: nr,nc = ar+dr,ac+dc if 0
def solution(board, skill): R,C = len(board),len(board[0]) imos = [[0]*(R+1) for _ in range(C+1)] for type,r1,c1,r2,c2,degree in skill: if type == 1: imos[r1][c1] -= degree imos[r1][c2+1] += degree imos[r2+1][c1] += degree imos[r2+1][c2+1] -= degree if type == 2: imos[r1][c1] += degree imos[r1][c2+1] -= degree imos[r2+1][c1] -= degree imos[r2+1][c2+1] += degree for i in range(len(imos)): for j i..
from collections import deque def solution(info, edges): tree = [[] for _ in range(len(info))] for a,b in edges: tree[a].append(b) q = deque([(1,0,tuple([1]+[0]*(len(info)-1)))]) visited = set() while q: s,w,visit = q.popleft() if s == w: continue if (s,w,visit) in visited: continue visited.add((s,w,visit)) for i in range(len(info)): if visit[i] == 1: for j in tree[i]: if not visit[j]: temp = li..
def dfs(n, info, k, apeach, lion, temp): if n == 0: global max_val, answer if lion - apeach > max_val: max_val = lion - apeach answer = temp[:] elif lion - apeach == max_val and max_val != 0: for i in range(10, -1, -1): if temp[i] > answer[i]: answer = temp[:] break elif temp[i] info[i]: temp[i] = info[i] + 1 if info[i] > 0: dfs(n - temp[i]..
from collections import defaultdict import math def time_to_minutes(time): time = time.split(':') return 60*int(time[0]) + int(time[1]) def solution(fees, records): cars = defaultdict(list) answer = [] for record in records: record = record.split() time = time_to_minutes(record[0]) cars[int(record[1])].append(time) for num in sorted(cars.keys()): if len(cars[num])%2 != 0: cars[num].append(1439) ..
def convert(n, k): s = '' while n: s += str(n%k) n //= k return s[::-1] def isprime(num): if num == 1: return False i = 2 while i*i s 2. s를 '0'을 기준으로 나눈 배열의 각 값이 소수인지 검사합니다
def solution(id_list, report, k): answer = [] id_dict = {x:[] for x in id_list} reported_id = {x:0 for x in id_list} report = set(report) for id in report: id = id.split() reported_id[id[1]] += 1 id_dict[id[0]].append(id[1]) for id in id_list: cnt = 0 for reportid in id_dict[id]: if reported_id[reportid] >= k: cnt += 1 answer.append(cnt) return answer 중복 제거를 위해 report 리스트를 set으로 바꿔줍니다. id_dict[신..