Created
July 17, 2020 15:46
-
-
Save inspirit941/8c82a5e57a6610b3b69e9bee79ce4b9c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import sys | |
from collections import deque | |
r, c, n = map(int, sys.stdin.readline().split()) | |
bombs = [] | |
maps = [] | |
for y in range(r): | |
maps.append(list(sys.stdin.readline().replace("\n",""))) | |
for x in range(len(maps[0])): | |
if maps[y][x] == 'O': | |
maps[y][x] = (0+3, maps[y][x]) | |
else: | |
maps[y][x] = (0, maps[y][x]) | |
def spread(time): | |
for y in range(len(maps)): | |
for x in range(len(maps[0])): | |
if maps[y][x][1] == '.': | |
maps[y][x] = (time+3, 'O') | |
def explode(time): | |
bombs = deque() | |
for y in range(len(maps)): | |
for x in range(len(maps[0])): | |
if maps[y][x][0] == time: | |
bombs.append((y,x)) | |
dirs = [(0,1),(0,-1),(1,0),(-1,0)] | |
while bombs: | |
y, x = bombs.popleft() | |
for dy, dx in dirs: | |
ny, nx = y+dy, x+dx | |
if 0 <= ny < len(maps) and 0 <= nx < len(maps[0]): | |
maps[ny][nx] = (time, ".") | |
maps[y][x] = (time, ".") | |
time = 1 | |
build = True | |
while time <= n: | |
if time == 1: | |
time += 1 | |
continue | |
if build: | |
build = False | |
spread(time) | |
else: | |
build = True | |
explode(time) | |
time += 1 | |
for y in range(len(maps)): | |
print("".join([i[1] for i in maps[y]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment