본문 바로가기

전체 글293

[Programmers] 2022 KAKAO BLIND RECRUITMENT - 사라지는 발판 코드def solution(board, aloc, bloc): M, N = len(board), len(board[0]) directions = [(1, 0), (-1, 0), (0, 1), (0, -1)] def dfs(cur_r, cur_c, opp_r, opp_c): # 현재 플레이어가 서 있는 발판이 이미 사라졌다면 패배 if board[cur_r][cur_c] == 0: return False, 0 can_move = False is_win = False min_dist = float('inf') max_dist = 0 board[.. 2026. 4. 22.
[Programmers] 2022 KAKAO BLIND RECRUITMENT - 파괴되지 않은 건물 코드def solution(board, skill): M, N = len(board), len(board[0]) temp = [[0] * (N + 1) for _ in range(M + 1)] for skill_type, r1, c1, r2, c2, degree in skill: d = degree if skill_type == 2 else -degree temp[r1][c1] += d temp[r1][c2 + 1] -= d temp[r2 + 1][c1] -= d temp[r2 + 1][c2 + 1] += d # 가로 누적 합 for i in range(M): for j in.. 2026. 4. 22.
[Programmers] 2022 KAKAO BLIND RECRUITMENT - 양과 늑대 코드def solution(info, edges): n = len(info) adj = [[] for _ in range(n)] for u, v in edges: adj[u].append(v) max_sheep = 0 # 최대 양의 수 def dfs(curr_node, sheep, wolf, next_nodes): nonlocal max_sheep if info[curr_node] == 0: # 양 sheep += 1 else: # 늑대 wolf += 1 # 늑대가 양보다 같거나 .. 2026. 4. 22.
[삼성 SW 역량테스트] 메이즈 러너 Python 코드import sysinput = sys.stdin.readlinedef solve(): N, M, K = map(int, input().split()) board = [list(map(int, input().split())) for _ in range(N)] person_pos = {} # {참가자 id: (현재 행, 열)} for i in range(M): id = i + 1 r, c = map(int, input().split()) r, c = r-1, c-1 # 0-based person_pos[id] = (r, c) # 보드에 출구 좌표 표시 er, ec = map(int, input().split(.. 2026. 4. 12.
[삼성 SW 역량테스트] 색깔 트리 코드def get_score_of_mixed(mixed): """ 비트마스크 mixed에 켜진(존재하는) 색의 개수를 세어 그 제곱을 반환 - 색은 1~5 범위이므로 비트 1..5만 검사 """ cnt = 0 for i in range(1, 6): if mixed & (1 latest: color = self.color latest = self.colored_time total = 0 mixed_color = 1 Python 코드 IIimport sysinput = sys.stdin.readlineclass Node: def __init__(self, mid, color, m.. 2026. 4. 10.
[삼성 SW 역량테스트] 마법의 숲 탐색 코드import sysfrom collections import dequeinput = sys.stdin.readlinedef solve(): R, C, K = map(int, input().split()) # 숲의 상태 (0: 빈칸, 1~K: 골렘 번호) (0, 1, 2행은 숲 밖) board = [[0] * (C + 1) for _ in range(R + 4)] is_exit = [[False] * (C + 1) for _ in range(R + 4)] # 북, 동, 남, 서 dr = [-1, 0, 1, 0] dc = [0, 1, 0, -1] total_score = 0 for k in range(1, K + 1): ci, di = .. 2026. 4. 9.
[삼성 SW 역량테스트] 코드트리 투어 코드import sysfrom collections import dequeimport heapqinput = sys.stdin.readlineINF = float('inf')def solve(): Q = int(input().strip()) adj = [] dist = [] products = {} # 여행 상품 ({id: [revenue, dest, is_deleted]}) pq = [] # (-profit, id) for _ in range(Q): parts = list(map(int, input().split())) com = parts[0] if com == 100: n, m = parts[1], parts[.. 2026. 4. 9.
[삼성 SW 역량테스트] 고대 문명 유적 탐사 코드import sysfrom collections import dequeinput = sys.stdin.readline# 1. 탐사 진행def explore(board): new_board = board[:] pq = [] # 1차 획득 가치, 회전 각도, 행, 열 for r in range(1, 4): # 열이 가장 작은 구간을 먼저 선택하고 행이 가장 작은 구간을 선택할 것이므로 for c in range(1, 4): for i in range(3): # (r, c) 중심으로 3*3 영역 90도씩 회전하면서 turn_90(r, c, new_board) score, hi.. 2026. 4. 8.