Skip to content

Commit

Permalink
solve(programmers): LV2_250136_석유_시추_py
Browse files Browse the repository at this point in the history
  • Loading branch information
gogumaC committed Mar 28, 2024
1 parent d1c680e commit ed203a3
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/programmers/level_1/DFS/LV2_석유_시추.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from collections import deque

oil=[]

of=[[0,1],[1,0],[-1,0],[0,-1]]
dc={}

def dfs(mark,x,y,land):
s=deque()
s.append([x,y])
oil[x][y]=mark
count=1
while len(s)>0:
x,y=s.pop()

for ox,oy in of:
nx=x+ox
ny=y+oy
if nx in range(len(land)) and ny in range(len(land[0])) and land[nx][ny]==1 and oil[nx][ny]==0:
oil[nx][ny]=mark
count+=1
s.append([nx,ny])
dc[mark]=count

def solution(land):

global oil
oil=[[0]*len(land[0]) for _ in land]

mark=1

for i in range(len(land[0])):
for j in range(len(land)):
if oil[j][i]==0 and land[j][i]==1:
dfs(mark,j,i,land)
mark+=1

maxv=0
for i in range(len(land[0])):
s=set([ oil[j][i] for j in range(len(land)) if land[j][i]==1 ])
sumv=sum([dc[m] for m in s])
maxv=max(maxv,sumv)

answer = maxv
return answer

0 comments on commit ed203a3

Please sign in to comment.