Skip to content

Commit

Permalink
Add kattis prob amoebas in py3
Browse files Browse the repository at this point in the history
  • Loading branch information
iandioch committed Mar 15, 2018
1 parent 22d6c63 commit cfc48b3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions kattis/amoebas/solution.py
@@ -0,0 +1,30 @@
y, x = map(int, input().split())
d = [[True if c == '#' else False for c in input()] for _ in range(y)]
col = [[None for _ in range(x)] for _ in range(y)]

maxcol = 0

def flood(i, j, colour):
if i < 0 or j < 0 or i >= x or j >= y:
return
if not d[j][i]:
return
if col[j][i]:
return
col[j][i] = colour
flood(i+1, j, colour)
flood(i+1, j-1, colour)
flood(i+1, j+1, colour)
flood(i, j-1, colour)
flood(i, j+1, colour)
flood(i-1, j, colour)
flood(i-1, j-1, colour)
flood(i-1, j+1, colour)

for i in range(x):
for j in range(y):
if d[j][i] and not col[j][i]:
maxcol += 1
flood(i, j, maxcol)

print(maxcol)

0 comments on commit cfc48b3

Please sign in to comment.