-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path21610.py
More file actions
104 lines (76 loc) · 2.16 KB
/
21610.py
File metadata and controls
104 lines (76 loc) · 2.16 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
n, m = map(int, input().split())
buckets = [[] for _ in range(n)]
for i in range(n):
buckets[i] = list(map(int, input().split()))
move = []
for i in range(m):
d, s = map(int, input().split())
move.append((d, s))
cloud = [[False] * n for _ in range(n)]
cloud[n-1][0] = True
cloud[n-1][1] = True
cloud[n-2][0] = True
cloud[n-2][1] = True
dx = [0] + [0, -1, -1, -1, 0, 1, 1, 1]
dy = [0] + [-1, -1, 0, 1, 1, 1, 0, -1]
def move_cloud(d, s):
global cloud
new_cloud = [[False] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if cloud[i][j]:
nx = (i + dx[d] * s) % n
ny = (j + dy[d] * s) % n
new_cloud[nx][ny] = True
cloud = new_cloud
for i in range(n):
for j in range(n):
if cloud[i][j]:
buckets[i][j] += 1
def rain_dance():
global cloud
cross_x = [-1, -1, 1, 1]
cross_y = [-1, 1, -1, 1]
new_cloud = [[False] * n for _ in range(n)]
for i in range(n):
for j in range(n):
if cloud[i][j]:
count = 0
for k in range(4):
nx = i + cross_x[k]
ny = j + cross_y[k]
if 0 <= nx < n and 0 <= ny < n and buckets[nx][ny]:
count += 1
buckets[i][j] += count
for i in range(n):
for j in range(n):
if buckets[i][j] >= 2 and not cloud[i][j]:
new_cloud[i][j] = True
buckets[i][j] -= 2
cloud = new_cloud
for i in range(m):
# print(f"***{i}번째 move***")
d, s = move[i]
# print(f"d: {d} s: {s}")
# print("buckets")
# for b in buckets:
# print(b)
# print("before cloud:")
# for c in cloud:
# print(c)
move_cloud(d, s)
# print("after cloud")
# for c in cloud:
# print(c)
rain_dance()
# print("after rain dance buckets")
# for b in buckets:
# print(b)
# print("after rain dance cloud")
# for c in cloud:
# print(c)
result = 0
for i in range(n):
for j in range(n):
result += buckets[i][j]
print(result)