๐น ๋ฏธ์ธ๋จผ์ง ์๋ !
1. ๋ฌธ์ ๋งํฌ
17144๋ฒ: ๋ฏธ์ธ๋จผ์ง ์๋ !
2. ์ฝ๋
Python3
31256KB
4372ms
PyPy3
165244KB
728ms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
R, C, T = map(int, input().split())
room = []
air_cleaner = []
for i in range(R):
line = list(map(int, input().split()))
if -1 in line:
air_cleaner.append(i)
room.append(line)
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
# ๋ฏธ์ธ๋จผ์ง ํ์ฐ
def diffusion(x, y):
count = 0
move_amount = room[x][y] // 5
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
# ๋ฒฝ์ ์ ๋ถ๋ชํ๊ณ ๊ณต๊ธฐ ์ฒญ์ ๊ธฐ ์๋ ์ ํ์ฐ
if 0 <= nx < R and 0 <= ny < C and room[nx][ny] != -1:
count += 1
dust[nx][ny][1] += move_amount # ํ์ฐ
dust[x][y][0] = move_amount * count # ํ์ฐ๋๊ณ ์ค์ ์
# ๊ณต๊ธฐ์ฒญ์ ๊ธฐ ์๋
def air_clean():
# ๋ฐ์๊ณ ๋ฐฉํฅ
for i in range(air_cleaner[0], 0, -1):
room[i][0], room[i-1][0] = room[i-1][0], room[i][0]
for i in range(0, C-1):
room[0][i], room[0][i+1] = room[0][i+1], room[0][i]
for i in range(0, air_cleaner[0]):
room[i][C-1], room[i+1][C-1] = room[i+1][C-1], room[i][C-1]
for i in range(C-1, 0, -1):
room[air_cleaner[0]][i], room[air_cleaner[0]][i-1] = room[air_cleaner[0]][i-1], room[air_cleaner[0]][i]
room[air_cleaner[0]][1] = 0 # ๊นจ๋ํ ๋ฐ๋
# ์๊ณ ๋ฐฉํฅ
for i in range(air_cleaner[1], R-1):
room[i][0], room[i+1][0] = room[i+1][0], room[i][0]
for i in range(0, C-1):
room[R-1][i], room[R-1][i+1] = room[R-1][i+1], room[R-1][i]
for i in range(R-1, air_cleaner[1], -1):
room[i][C-1], room[i-1][C-1] = room[i-1][C-1], room[i][C-1]
for i in range(C-1, 0, -1):
room[air_cleaner[1]][i], room[air_cleaner[1]][i-1] = room[air_cleaner[1]][i-1], room[air_cleaner[1]][i]
room[air_cleaner[1]][1] = 0 # ๊นจ๋ํ ๋ฐ๋
while T:
T -= 1
# ์ค์ด๋ค ๋จผ์ง ์, ๋์ด๋ ๋จผ์ง ์
dust = [[[0, 0] for _ in range(C)] for _ in range(R)]
# ๋ฏธ์ธ๋จผ์ง ์ด๋ ํ์ธ
for i in range(R):
for j in range(C):
if room[i][j] > 0:
diffusion(i, j)
# ๋ฏธ์ธ๋จผ์ง ํ์ฐ ์ ๋ฆฌ
for i in range(R):
for j in range(C):
# ๋ณ๋์ฌํญ์ด ์์ ๋
if dust[i][j] != [0, 0]:
room[i][j] -= dust[i][j][0]
room[i][j] += dust[i][j][1]
air_clean()
# ๋จ์์๋ ๋ฏธ์ธ๋จผ์ง ์
result = 0
for i in range(R):
for j in range(C):
if room[i][j] > 0:
result += room[i][j]
print(result)
3. ํด์ค
์๋ฎฌ๋ ์ด์ ์ ์ฌ์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ค.
๋ฏธ์ธ๋จผ์ง๊ฐ ํ์ฐ๋ ๋ ๋ชจ๋ ๋ฐฉ์ ๋ฏธ์ธ๋จผ์ง๊ฐ ํ์ฐ๋๊ธฐ ์ ์ ๊ฐ์ด ๋ณ๊ฒฝ๋๋ฉด ์ต์ข ๊ฐ์ด ๋ค๋ฅด๊ฒ ๋์ค๋ฏ๋ก dust 3์ฐจ์ ๋ฐฐ์ด์ ๊ฐ ์์น์ ์ค์ด๋ค ๋จผ์ง์, ๋์ด๋ ๋จผ์ง์ ๊ฐ์ ๋ด์๋์๋ค.
๊ณต๊ธฐ ์ฒญ์ ๊ธฐ๊ฐ ๋ ๋ ๋๋ ๋ฐฉํฅ๊ณผ ๋ฐ๋ ๋ฐฉํฅ์ผ๋ก ์ด๋ํ๋ฉด์ ๊ฐ์ ์ค์์นญ ํด์ฃผ์๋ค. ํ ๋ฐํด๋ฅผ ๋์์ผ๋ฉด ๊ณต๊ธฐ์ฒญ์ ๊ธฐ์ ๋ฐ๋ ์์ ์์น์ ๊ฐ๋ง 0์ผ๋ก ๋ณ๊ฒฝํด์ค๋ค. (๊ณต๊ธฐ ์ฒญ์ ๊ธฐ์์ ๋์ค๋ ๋ฐ๋์ ๊นจ๋ํ ๋ฐ๋์ด๋ฏ๋ก)
์์ ๊ณผ์ ์ T ์๊ฐ๋์ ๋ฐ๋ณตํด์ค๋ค.
This post is licensed under CC BY 4.0 by the author.