Created
October 26, 2021 12:31
-
-
Save manji-0/a2a634f1a3beb27e24ef85479c2f3e02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Python 3.9.5 | |
W, H = [ int(x) for x in input().split(" ") ] | |
MAP = [] | |
start_w = 0 | |
start_h = 0 | |
for i in range(H): | |
row = list(input()) | |
MAP.append(row) | |
for j, value in enumerate(row): | |
if value == "@": | |
start_w = j | |
start_h = i | |
def dfs(w, h): | |
count = 0 | |
if MAP[h][w] == "#": | |
return 0 | |
else: | |
count += 1 | |
MAP[h][w] = "#" | |
if w != 0: | |
count += dfs(w-1, h) | |
if w != W - 1: | |
count += dfs(w+1, h) | |
if h != 0: | |
count += dfs(w, h-1) | |
if h != H - 1: | |
count += dfs(w, h+1) | |
return count | |
print(dfs(start_w, start_h)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment