Skip to content

Commit ff23a12

Browse files
committed
미생물 격리
1 parent 841a724 commit ff23a12

File tree

3 files changed

+337
-0
lines changed

3 files changed

+337
-0
lines changed

swea/2382/2382.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import os
2+
import sys
3+
4+
sys.stdin = open(
5+
os.path.join("/", *__file__.split("/")[:-1], "sample_input.txt"), "r"
6+
)
7+
8+
# https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV597vbqAH0DFAVl
9+
10+
11+
DR = [-1, 1, 0, 0]
12+
DC = [0, 0, -1, 1]
13+
14+
15+
class Cluster:
16+
def __init__(self, r: int, c: int, n: int, d: int):
17+
self.loc = (r, c)
18+
self.n = n
19+
self.d = d - 1
20+
21+
def __iadd__(self, other):
22+
self.n += other.n
23+
return self
24+
25+
def __repr__(self):
26+
return str(self.n)
27+
28+
29+
def is_boundary(r: int, c: int):
30+
return r == 0 or r == m - 1 or c == 0 or c == m - 1
31+
32+
33+
def step():
34+
cluster_map = [[0 for _ in range(m)] for _ in range(m)]
35+
for _id in sorted(
36+
list(clusters.keys()), key=lambda _id: clusters[_id].n, reverse=True
37+
):
38+
cluster = clusters[_id]
39+
40+
r, c = cluster.loc
41+
_r, _c = r + DR[cluster.d], c + DC[cluster.d]
42+
43+
if is_boundary(_r, _c):
44+
cluster.n //= 2
45+
cluster.d ^= 1
46+
47+
if cluster_map[_r][_c]:
48+
clusters[cluster_map[_r][_c]] += cluster
49+
clusters.pop(_id)
50+
continue
51+
52+
if not cluster.n:
53+
clusters.pop(_id)
54+
continue
55+
56+
cluster.loc = (_r, _c)
57+
cluster_map[_r][_c] = _id
58+
59+
60+
for t in range(1, int(input()) + 1):
61+
m, n, k = map(int, input().split())
62+
clusters = {
63+
_id: Cluster(*map(int, input().split())) for _id in range(1, k + 1)
64+
}
65+
for _ in range(n):
66+
step()
67+
68+
print(f"#{t} {sum(cluster.n for cluster in clusters.values())}")

swea/2382/sample_input.txt

+259
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
10
2+
7 2 9
3+
1 1 7 1
4+
2 1 7 1
5+
5 1 5 4
6+
3 2 8 4
7+
4 3 14 1
8+
3 4 3 3
9+
1 5 8 2
10+
3 5 100 1
11+
5 5 1 1
12+
10 17 46
13+
7 5 724 2
14+
7 7 464 3
15+
2 2 827 2
16+
2 4 942 4
17+
4 5 604 4
18+
7 2 382 1
19+
6 5 895 3
20+
8 7 538 4
21+
6 1 299 4
22+
4 7 811 4
23+
3 6 664 2
24+
6 8 868 2
25+
7 6 859 2
26+
4 6 778 2
27+
5 4 842 3
28+
1 3 942 1
29+
1 1 805 3
30+
3 2 350 3
31+
2 5 623 2
32+
5 3 840 1
33+
7 1 308 4
34+
1 8 323 3
35+
2 3 82 3
36+
2 6 115 2
37+
8 3 930 1
38+
6 2 72 1
39+
2 1 290 3
40+
4 8 574 4
41+
8 5 150 3
42+
8 2 287 2
43+
2 8 909 2
44+
2 7 588 2
45+
7 3 30 3
46+
5 8 655 3
47+
3 8 537 1
48+
4 2 350 3
49+
5 6 199 1
50+
5 5 734 2
51+
3 3 788 1
52+
8 4 893 1
53+
1 4 421 4
54+
6 3 616 2
55+
1 2 556 4
56+
7 8 8 1
57+
5 2 702 2
58+
4 4 503 3
59+
10 5 28
60+
3 3 796 1
61+
7 2 798 2
62+
2 6 622 1
63+
3 5 179 3
64+
7 8 888 4
65+
5 8 634 3
66+
1 8 646 1
67+
3 7 433 4
68+
6 7 416 1
69+
2 7 651 3
70+
6 4 476 2
71+
5 6 712 4
72+
1 7 869 4
73+
6 1 789 2
74+
8 8 585 3
75+
7 6 426 1
76+
1 5 154 2
77+
1 2 692 1
78+
2 4 549 3
79+
2 1 60 2
80+
4 8 996 4
81+
8 2 437 2
82+
3 6 195 2
83+
1 3 734 4
84+
3 8 355 2
85+
1 1 945 1
86+
2 5 558 2
87+
7 7 144 2
88+
10 22 26
89+
2 2 450 4
90+
6 3 659 1
91+
5 8 24 2
92+
3 7 649 2
93+
3 2 22 3
94+
1 3 905 4
95+
7 8 625 3
96+
6 7 824 3
97+
7 3 159 1
98+
2 7 297 4
99+
7 2 270 2
100+
4 5 985 1
101+
7 1 627 2
102+
3 4 625 4
103+
8 5 972 4
104+
6 6 432 4
105+
6 8 142 1
106+
7 7 900 1
107+
4 1 974 2
108+
4 2 760 4
109+
1 4 550 2
110+
5 7 624 4
111+
4 6 694 1
112+
4 3 593 3
113+
3 1 152 4
114+
1 8 926 1
115+
10 7 15
116+
3 4 227 1
117+
4 7 109 1
118+
3 7 487 2
119+
2 3 627 2
120+
6 1 520 4
121+
7 3 596 4
122+
2 6 525 4
123+
1 5 116 3
124+
7 7 771 4
125+
4 4 520 2
126+
7 5 763 1
127+
5 4 829 3
128+
5 2 578 3
129+
6 8 200 2
130+
3 8 760 4
131+
10 24 12
132+
6 5 887 2
133+
2 3 428 1
134+
2 1 540 2
135+
8 1 356 4
136+
1 7 485 4
137+
5 1 357 3
138+
7 6 271 2
139+
6 2 22 1
140+
6 1 41 2
141+
8 2 565 2
142+
8 5 855 1
143+
6 3 734 1
144+
10 22 44
145+
2 2 963 1
146+
8 4 635 4
147+
4 1 938 4
148+
8 7 511 3
149+
6 8 825 4
150+
6 7 934 3
151+
3 7 701 4
152+
2 7 534 2
153+
5 2 705 1
154+
3 5 300 2
155+
6 2 855 4
156+
7 7 877 4
157+
1 7 443 1
158+
1 2 313 1
159+
3 3 932 2
160+
1 8 831 2
161+
1 1 90 2
162+
2 6 145 3
163+
2 3 740 4
164+
5 3 759 4
165+
1 6 181 1
166+
8 6 608 4
167+
5 6 556 2
168+
2 4 541 4
169+
2 1 174 2
170+
6 1 601 1
171+
7 5 84 4
172+
4 3 970 3
173+
8 8 503 1
174+
3 4 171 3
175+
5 7 913 4
176+
8 1 232 3
177+
7 6 539 4
178+
3 8 648 1
179+
8 2 944 2
180+
2 5 508 2
181+
5 1 87 1
182+
5 8 88 4
183+
2 8 681 2
184+
1 5 758 2
185+
3 1 690 3
186+
6 4 620 3
187+
5 4 783 1
188+
6 6 748 1
189+
10 9 38
190+
2 7 955 1
191+
7 7 25 4
192+
4 2 496 2
193+
1 4 342 1
194+
7 5 72 1
195+
3 7 429 2
196+
5 2 812 3
197+
8 6 36 2
198+
1 6 994 3
199+
1 5 838 1
200+
3 4 131 4
201+
7 2 11 2
202+
6 3 650 3
203+
7 3 353 2
204+
1 7 454 2
205+
8 3 256 4
206+
5 5 213 2
207+
6 5 80 1
208+
2 1 676 4
209+
4 6 561 3
210+
2 5 653 3
211+
3 5 923 3
212+
8 2 259 3
213+
4 4 781 2
214+
1 1 313 2
215+
3 6 938 3
216+
2 6 700 3
217+
4 1 215 2
218+
4 8 39 3
219+
5 1 954 3
220+
6 7 774 1
221+
5 8 541 4
222+
3 1 885 4
223+
7 8 867 2
224+
2 8 825 1
225+
5 6 598 3
226+
6 6 80 3
227+
8 1 405 2
228+
10 16 11
229+
5 7 87 3
230+
2 5 686 1
231+
6 7 64 2
232+
6 8 873 3
233+
5 6 762 2
234+
8 4 268 3
235+
7 3 307 4
236+
1 7 809 3
237+
5 5 293 3
238+
5 1 345 3
239+
4 1 114 4
240+
10 8 19
241+
3 1 52 4
242+
6 8 423 3
243+
7 3 498 4
244+
7 5 633 3
245+
7 7 392 3
246+
6 6 458 4
247+
3 8 830 3
248+
5 1 799 3
249+
1 1 540 3
250+
4 8 567 3
251+
1 6 897 3
252+
5 4 230 1
253+
2 6 229 3
254+
1 5 147 1
255+
4 1 754 2
256+
3 3 569 1
257+
7 8 515 4
258+
2 4 528 4
259+
2 1 962 2

swea/2382/sample_output.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#1 145
2+
#2 5507
3+
#3 9709
4+
#4 2669
5+
#5 3684
6+
#6 774
7+
#7 4797
8+
#8 8786
9+
#9 1374
10+
#10 5040

0 commit comments

Comments
 (0)