From 29a4c2f37916c34a9943ee13f58f39d299be2777 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Tue, 7 Oct 2025 23:39:15 +0900 Subject: [PATCH] 20251007 baekjoon --- code_study/Baekjoon/python/14502.py | 50 +++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 code_study/Baekjoon/python/14502.py diff --git a/code_study/Baekjoon/python/14502.py b/code_study/Baekjoon/python/14502.py new file mode 100644 index 0000000..b625a8a --- /dev/null +++ b/code_study/Baekjoon/python/14502.py @@ -0,0 +1,50 @@ +from itertools import combinations +from collections import deque +import copy +import sys +input = sys.stdin.readline + +N, M = map(int, input().split()) +all_axis: list[tuple[int, int]] = [] +lab_origin: list[list[int]] = [] +virus: list[tuple[int, int]] = [] + +for i in range(N) : + lab_origin.append(list(map(int, input().split()))) + for j in range(M) : + if lab_origin[i][j] == 2 : + virus.append((i,j)) + elif lab_origin[i][j] != 1 : + all_axis.append((i,j)) + +maxArea = 0 +dx = [-1,1,0,0] +dy = [0,0,-1,1] + +for wall_comb in combinations(all_axis, 3) : + lab_copy = copy.deepcopy(lab_origin) + + for y, x in wall_comb: + lab_copy[y][x] = 1 + + q = deque() + for v in virus : + q.append(v) + + while q : + cy, cx = q.popleft() + + for i in range(4) : + ny, nx = cy + dy[i], cx + dx[i] + + if 0<=ny