๐ฆ ๊ฑฐ๋ฆฌ๋๊ธฐ ํ์ธํ๊ธฐ
1. ๋ฌธ์ ๋งํฌ
2. ์ฝ๋
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
def solution(places):
answer = []
for MAP in places:
persons = []
for i in range(5):
for j in range(5):
if MAP[i][j] == 'P':
persons.append((i, j))
answer.append(check(MAP, persons))
return answer
def check(MAP, persons):
for i in range(len(persons) - 1):
x1, y1 = persons[i]
for j in range(i + 1, len(persons)):
x2, y2 = persons[j]
diff_x = abs(x1 - x2)
diff_y = abs(y1 - y2)
dist = diff_x + diff_y
# ๋ถ์ด์์ผ๋ฉด ๊ฑฐ๋ฆฌ๋๊ธฐ ์์งํด
if dist < 2:
return 0
if dist == 2:
# ๊ฐ๋ก๋ก ์ ๋ ฌ
if diff_x == 2 and MAP[min(x1, x2) + 1][y1] != 'X':
return 0
# ์ธ๋ก๋ก ์ ๋ ฌ
elif diff_y == 2 and MAP[x1][min(y1, y2) + 1] != 'X':
return 0
# ๋๊ฐ์ ์ผ๋ก
elif MAP[x1][y2] == 'O' or MAP[x2][y1] == 'O':
return 0
return 1
์คํ ๊ฒฐ๊ณผ
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
์ฑ์ ์ ์์ํฉ๋๋ค. ์ ํ์ฑ ํ ์คํธ ํ ์คํธ 1 ใ ํต๊ณผ (0.10ms, 10.1MB) ํ ์คํธ 2 ใ ํต๊ณผ (0.06ms, 10.4MB) ํ ์คํธ 3 ใ ํต๊ณผ (0.03ms, 10.3MB) ํ ์คํธ 4 ใ ํต๊ณผ (0.06ms, 10.3MB) ํ ์คํธ 5 ใ ํต๊ณผ (0.05ms, 10.2MB) ํ ์คํธ 6 ใ ํต๊ณผ (0.03ms, 10.2MB) ํ ์คํธ 7 ใ ํต๊ณผ (0.03ms, 10.3MB) ํ ์คํธ 8 ใ ํต๊ณผ (0.05ms, 10.2MB) ํ ์คํธ 9 ใ ํต๊ณผ (0.03ms, 10.3MB) ํ ์คํธ 10 ใ ํต๊ณผ (0.03ms, 10.3MB) ํ ์คํธ 11 ใ ํต๊ณผ (0.03ms, 10.2MB) ํ ์คํธ 12 ใ ํต๊ณผ (0.03ms, 10.3MB) ํ ์คํธ 13 ใ ํต๊ณผ (0.03ms, 10.2MB) ํ ์คํธ 14 ใ ํต๊ณผ (0.03ms, 10.4MB) ํ ์คํธ 15 ใ ํต๊ณผ (0.03ms, 10.1MB) ํ ์คํธ 16 ใ ํต๊ณผ (0.04ms, 10.2MB) ํ ์คํธ 17 ใ ํต๊ณผ (0.04ms, 10.2MB) ํ ์คํธ 18 ใ ํต๊ณผ (0.03ms, 10.4MB) ํ ์คํธ 19 ใ ํต๊ณผ (0.04ms, 10.2MB) ํ ์คํธ 20 ใ ํต๊ณผ (0.07ms, 10.1MB) ํ ์คํธ 21 ใ ํต๊ณผ (0.03ms, 10.3MB) ํ ์คํธ 22 ใ ํต๊ณผ (0.03ms, 10.3MB) ํ ์คํธ 23 ใ ํต๊ณผ (0.02ms, 10.1MB) ํ ์คํธ 24 ใ ํต๊ณผ (0.03ms, 10.2MB) ํ ์คํธ 25 ใ ํต๊ณผ (0.03ms, 10.2MB) ํ ์คํธ 26 ใ ํต๊ณผ (0.03ms, 10.3MB) ํ ์คํธ 27 ใ ํต๊ณผ (0.03ms, 10.2MB) ํ ์คํธ 28 ใ ํต๊ณผ (0.03ms, 10.1MB) ํ ์คํธ 29 ใ ํต๊ณผ (0.03ms, 10.4MB) ํ ์คํธ 30 ใ ํต๊ณผ (0.04ms, 10.4MB) ํ ์คํธ 31 ใ ํต๊ณผ (0.03ms, 10.2MB) ์ฑ์ ๊ฒฐ๊ณผ ์ ํ์ฑ: 100.0 ํฉ๊ณ: 100.0 / 100.0
3. ํด์ค
ํด์ค
๋งจํดํผ ๊ฑฐ๋ฆฌ๊ฐ 2 ๋ฏธ๋ง์ผ ๊ฒฝ์ฐ ๋ฑ ๋ถ์ด ์๋ ๊ฒ์ผ๋ก ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค์ง ์์
๋งจํดํผ ๊ฑฐ๋ฆฌ๊ฐ 2์ผ ๊ฒฝ์ฐ ํ์ค์ ์์ ๊ฒฝ์ฐ ํํฐ์ ์ด 1๊ฐ,
๋๊ฐ์ ์ผ ๊ฒฝ์ฐ ํํฐ์ ์ด 2๊ฐ๊ฐ ์์ด์ผํจ
๊ทธ๊ฒ์ ๊ฒ์ฌ
This post is licensed under CC BY 4.0 by the author.