Created
May 18, 2020 04:03
-
-
Save inspirit941/009abc44aaa67379c825a7cd99e8859a 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 itertools import chain | |
r, c, t = map(int, sys.stdin.readline().split()) | |
maps = [list(map(int, sys.stdin.readline().split())) for _ in range(r)] | |
pos = 0 | |
# 공기청정기 위치 확인 | |
for y in range(r): | |
if maps[y][0] == -1: | |
pos = y | |
break | |
def rotate(cy): | |
# 반시계 | |
for y in range(cy-1, 0, -1): | |
maps[y][0] = maps[y-1][0] | |
maps[0][:-1] = maps[0][1:] | |
for y in range(cy): | |
maps[y][-1] = maps[y+1][-1] | |
maps[cy][2:] = maps[cy][1:-1] | |
maps[cy][1] = 0 | |
cy += 1 | |
# 시계 | |
for y in range(cy+1, len(maps)-1): | |
maps[y][0] = maps[y+1][0] | |
maps[-1][:-1] = maps[-1][1:] | |
for y in range(len(maps)-1, cy, -1): | |
maps[y][-1] = maps[y-1][-1] | |
maps[cy][2:] = maps[cy][1:-1] | |
maps[cy][1] = 0 | |
dirs = [(0,1),(0,-1),(1,0),(-1,0)] | |
for _ in range(t): | |
update_value = [[0 for _ in range(c)] for _ in range(r)] | |
# 미세먼지 이동 | |
for y in range(r): | |
for x in range(c): | |
if maps[y][x] >= 5: | |
for dy, dx in dirs: | |
ny, nx = y + dy, x + dx | |
if 0 <= ny < r and 0 <= nx < c and maps[ny][nx] != -1: | |
update_value[ny][nx] += maps[y][x] // 5 | |
update_value[y][x] -= maps[y][x] // 5 | |
# 이동한 미세먼지 반영 | |
for y in range(r): | |
for x in range(c): | |
maps[y][x] += update_value[y][x] | |
# 공기청정기 작동 | |
rotate(pos) | |
print(sum(chain(*maps))+2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment