반응형
https://www.acmicpc.net/problem/17144
x_lim, y_lim, t = map(int, input().split())
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
table = []
air_x = -1
for i in range(x_lim):
row = list(map(int, input().split()))
if row[0] == -1:
air_x = i
table.append(row)
assistant = [[0 for _ in range(y_lim)] for _ in range(x_lim)]
for _ in range(t):
## diffusion
assistant.clear()
assistant.extend([[0 for _ in range(y_lim)] for _ in range(x_lim)])
for x in range(x_lim):
for y in range(y_lim):
# checking dust
if table[x][y] > 0:
difussed = table[x][y] // 5
count = 0
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0<=nx<x_lim and 0<=ny<y_lim and table[nx][ny]!=-1:
count += 1
assistant[nx][ny] += difussed
table[x][y] -= difussed*count
for x in range(x_lim):
for y in range(y_lim):
table[x][y] += assistant[x][y]
## movement by wind
for i in range(air_x-2):
table[air_x-2-i][0] = table[air_x-3-i][0]
for i in range(y_lim-1):
table[0][i] = table[0][i+1]
for i in range(air_x-1):
table[i][y_lim-1] = table[i+1][y_lim-1]
for i in range(y_lim-2):
table[air_x-1][y_lim-i-1] = table[air_x-1][y_lim-i-2]
table[air_x-1][1] = 0
for i in range(x_lim - air_x-2):
table[air_x+1+i][0] = table[air_x+2+i][0]
for i in range(y_lim-1):
table[-1][i] = table[-1][i+1]
for i in range(x_lim - air_x-1):
table[-1-i][y_lim-1] = table[-2-i][y_lim-1]
for i in range(y_lim-2):
table[air_x][y_lim-i-1] = table[air_x][y_lim-i-2]
table[air_x][1] = 0
# answer
answer = 2
for x in range(x_lim):
for y in range(y_lim):
answer += table[x][y]
print(answer)
move를 일일이 구현해줘야해서 빡셌다.
댓글