20251007 baekjoon
This commit is contained in:
parent
9ab329938b
commit
29a4c2f379
50
code_study/Baekjoon/python/14502.py
Normal file
50
code_study/Baekjoon/python/14502.py
Normal file
@ -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<N and 0<=nx<M and lab_copy[ny][nx] == 0 :
|
||||
q.append((ny,nx))
|
||||
lab_copy[ny][nx] = 2
|
||||
|
||||
currentArea = 0
|
||||
for i in range(N) :
|
||||
currentArea += lab_copy[i].count(0)
|
||||
|
||||
maxArea = max(maxArea, currentArea)
|
||||
|
||||
print(maxArea)
|
||||
Loading…
x
Reference in New Issue
Block a user