๋ฌธ์ ์ค๋ช
๊ฐ๋ฐ์๋ฅผ ํฌ๋งํ๋ ์ฃ ๋ฅด๋๊ฐ ์นด์นด์ค์ ๋ฉด์ ์ ๋ณด๋ฌ ์์ต๋๋ค.
์ฝ๋ก๋ ๋ฐ์ด๋ฌ์ค ๊ฐ์ผ ์๋ฐฉ์ ์ํด ์์์๋ค์ ๊ฑฐ๋ฆฌ๋ฅผ ๋ฌ์ ๋๊ธฐ๋ฅผ ํด์ผํ๋๋ฐ ๊ฐ๋ฐ ์ง๊ตฐ ๋ฉด์ ์ธ ๋งํผ
์๋์ ๊ฐ์ ๊ท์น์ผ๋ก ๋๊ธฐ์ค์ ๊ฑฐ๋ฆฌ๋ฅผ ๋๊ณ ์๋๋ก ์๋ดํ๊ณ ์์ต๋๋ค.
- ๋๊ธฐ์ค์ 5๊ฐ์ด๋ฉฐ, ๊ฐ ๋๊ธฐ์ค์ 5x5 ํฌ๊ธฐ์ ๋๋ค.
- ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์ํ์ฌ ์์์๋ค ๋ผ๋ฆฌ๋ ๋งจํดํผ ๊ฑฐ๋ฆฌ1๊ฐ 2 ์ดํ๋ก ์์ง ๋ง์ ์ฃผ์ธ์.
- ๋จ ์์์๊ฐ ์์์๋ ์๋ฆฌ ์ฌ์ด๊ฐ ํํฐ์ ์ผ๋ก ๋งํ ์์ ๊ฒฝ์ฐ์๋ ํ์ฉํฉ๋๋ค.
์๋ฅผ ๋ค์ด,
์ ๊ทธ๋ฆผ์ฒ๋ผ ์๋ฆฌ ์ฌ์ด์ ํํฐ์ ์ด ์กด์ฌํ๋ค๋ฉด ๋งจํดํผ ๊ฑฐ๋ฆฌ๊ฐ 2์ฌ๋ ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํจ ๊ฒ์ ๋๋ค. | ์ ๊ทธ๋ฆผ์ฒ๋ผ ํํฐ์ ์ ์ฌ์ด์ ๋๊ณ ์์ ๊ฒฝ์ฐ๋ ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํจ ๊ฒ์ ๋๋ค. | ์ ๊ทธ๋ฆผ์ฒ๋ผ ์๋ฆฌ ์ฌ์ด๊ฐ ๋งจํดํผ ๊ฑฐ๋ฆฌ 2์ด๊ณ ์ฌ์ด์ ๋น ํ ์ด๋ธ์ด ์๋ ๊ฒฝ์ฐ๋ ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค์ง ์์ ๊ฒ์ ๋๋ค. |
์์์๊ฐ ์์์๋ ์๋ฆฌ(P)๋ฅผ ์๋ฏธํฉ๋๋ค. | ๋น ํ ์ด๋ธ(O)์ ์๋ฏธํฉ๋๋ค. | ํํฐ์ (X)์ ์๋ฏธํฉ๋๋ค. |
5๊ฐ์ ๋๊ธฐ์ค์ ๋ณธ ์ฃ ๋ฅด๋๋ ๊ฐ ๋๊ธฐ์ค์์ ์์์๋ค์ด ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์ ๊ธฐํค๊ณ ์๋์ง ์๊ณ ์ถ์ด์ก์ต๋๋ค. ์๋ฆฌ์ ์์์๋ ์์์๋ค์ ์ ๋ณด์ ๋๊ธฐ์ค ๊ตฌ์กฐ๋ฅผ ๋๊ธฐ์ค๋ณ๋ก ๋ด์ 2์ฐจ์ ๋ฌธ์์ด ๋ฐฐ์ด places๊ฐ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์ด์ง๋๋ค. ๊ฐ ๋๊ธฐ์ค๋ณ๋ก ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค๊ณ ์์ผ๋ฉด 1์, ํ ๋ช ์ด๋ผ๋ ์งํค์ง ์๊ณ ์์ผ๋ฉด 0์ ๋ฐฐ์ด์ ๋ด์ return ํ๋๋ก solution ํจ์๋ฅผ ์์ฑํด ์ฃผ์ธ์.
์ ํ ์ฌํญ
- places์ ํ ๊ธธ์ด(๋๊ธฐ์ค ๊ฐ์) = 5
- places์ ๊ฐ ํ์ ํ๋์ ๋๊ธฐ์ค ๊ตฌ์กฐ๋ฅผ ๋ํ๋ ๋๋ค.
- places์ ์ด ๊ธธ์ด(๋๊ธฐ์ค ์ธ๋ก ๊ธธ์ด) = 5
- places์ ์์๋ P,O,X๋ก ์ด๋ฃจ์ด์ง ๋ฌธ์์ด์
๋๋ค.
- places ์์์ ๊ธธ์ด(๋๊ธฐ์ค ๊ฐ๋ก ๊ธธ์ด) = 5
- P๋ ์์์๊ฐ ์์์๋ ์๋ฆฌ๋ฅผ ์๋ฏธํฉ๋๋ค.
- O๋ ๋น ํ ์ด๋ธ์ ์๋ฏธํฉ๋๋ค.
- X๋ ํํฐ์ ์ ์๋ฏธํฉ๋๋ค.
- ์ ๋ ฅ์ผ๋ก ์ฃผ์ด์ง๋ 5๊ฐ ๋๊ธฐ์ค์ ํฌ๊ธฐ๋ ๋ชจ๋ 5x5 ์ ๋๋ค.
- return ๊ฐ ํ์
- 1์ฐจ์ ์ ์ ๋ฐฐ์ด์ 5๊ฐ์ ์์๋ฅผ ๋ด์์ return ํฉ๋๋ค.
- places์ ๋ด๊ฒจ ์๋ 5๊ฐ ๋๊ธฐ์ค์ ์์๋๋ก, ๊ฑฐ๋ฆฌ๋๊ธฐ ์ค์ ์ฌ๋ถ๋ฅผ ์ฐจ๋ก๋๋ก ๋ฐฐ์ด์ ๋ด์ต๋๋ค.
- ๊ฐ ๋๊ธฐ์ค ๋ณ๋ก ๋ชจ๋ ์์์๊ฐ ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค๊ณ ์์ผ๋ฉด 1์, ํ ๋ช ์ด๋ผ๋ ์งํค์ง ์๊ณ ์์ผ๋ฉด 0์ ๋ด์ต๋๋ค.
์ ์ถ๋ ฅ ์
places | result |
[["POOOP", "OXXOX", "OPXPX", "OOXOX", "POXXP"], ["POOPX", "OXPXP", "PXXXO", "OXXXO", "OOOPP"], ["PXOPX", "OXOXP", "OXPOX", "OXXOP", "PXPOX"], ["OOOXX", "XOOOX", "OOOXX", "OXOOX", "OOOOO"], ["PXPXP", "XPXPX", "PXPXP", "XPXPX", "PXPXP"]] | [1, 0, 1, 1, 1] |
์ ์ถ๋ ฅ ์ ์ค๋ช
์ ์ถ๋ ฅ ์ #1
์ฒซ ๋ฒ์งธ ๋๊ธฐ์ค
No. | 0 | 1 | 2 | 3 | 4 |
0 | P | O | O | O | P |
1 | O | X | X | O | X |
2 | O | P | X | P | X |
3 | O | O | X | O | X |
4 | P | O | X | X | P |
- ๋ชจ๋ ์์์๊ฐ ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค๊ณ ์์ต๋๋ค.
๋ ๋ฒ์งธ ๋๊ธฐ์ค
No. | 0 | 1 | 2 | 3 | 4 |
0 | P | O | O | P | X |
1 | O | X | P | X | P |
2 | P | X | X | X | O |
3 | O | X | X | X | O |
4 | O | O | O | P | P |
- (0, 0) ์๋ฆฌ์ ์์์์ (2, 0) ์๋ฆฌ์ ์์์๊ฐ ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค๊ณ ์์ง ์์ต๋๋ค.
- (1, 2) ์๋ฆฌ์ ์์์์ (0, 3) ์๋ฆฌ์ ์์์๊ฐ ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค๊ณ ์์ง ์์ต๋๋ค.
- (4, 3) ์๋ฆฌ์ ์์์์ (4, 4) ์๋ฆฌ์ ์์์๊ฐ ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค๊ณ ์์ง ์์ต๋๋ค.
์ธ ๋ฒ์งธ ๋๊ธฐ์ค
No. | 0 | 1 | 2 | 3 | 4 |
0 | P | X | O | P | X |
1 | O | X | O | X | P |
2 | O | X | P | O | X |
3 | O | X | X | O | P |
4 | P | X | P | O | X |
- ๋ชจ๋ ์์์๊ฐ ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค๊ณ ์์ต๋๋ค.
๋ค ๋ฒ์งธ ๋๊ธฐ์ค
No. | 0 | 1 | 2 | 3 | 4 |
0 | O | O | O | X | X |
1 | X | O | O | O | X |
2 | O | O | O | X | X |
3 | O | X | O | O | X |
4 | O | O | O | O | O |
- ๋๊ธฐ์ค์ ์์์๊ฐ ์์ผ๋ฏ๋ก ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค๊ณ ์์ต๋๋ค.
๋ค์ฏ ๋ฒ์งธ ๋๊ธฐ์ค
No. | 0 | 1 | 2 | 3 | 4 |
0 | P | X | P | X | P |
1 | X | P | X | P | X |
2 | P | X | P | X | P |
3 | X | P | X | P | X |
4 | P | X | P | X | P |
- ๋ชจ๋ ์์์๊ฐ ๊ฑฐ๋ฆฌ๋๊ธฐ๋ฅผ ์งํค๊ณ ์์ต๋๋ค.
๋ ๋ฒ์งธ ๋๊ธฐ์ค์ ์ ์ธํ ๋ชจ๋ ๋๊ธฐ์ค์์ ๊ฑฐ๋ฆฌ๋๊ธฐ๊ฐ ์ง์ผ์ง๊ณ ์์ผ๋ฏ๋ก, ๋ฐฐ์ด [1, 0, 1, 1, 1]์ return ํฉ๋๋ค.
์ ํ์๊ฐ ์๋ด
- ์ ํ์ฑ ํ ์คํธ : 10์ด
โป ๊ณต์ง - 2022๋ 4์ 25์ผ ํ ์คํธ์ผ์ด์ค๊ฐ ์ถ๊ฐ๋์์ต๋๋ค.
๋ ํ ์ด๋ธ T1, T2๊ฐ ํ๋ ฌ (r1, c1), (r2, c2)์ ๊ฐ๊ฐ ์์นํ๊ณ ์๋ค๋ฉด, T1, T2 ์ฌ์ด์ ๋งจํดํผ ๊ฑฐ๋ฆฌ๋ |r1 - r2| + |c1 - c2| ์ ๋๋ค.
ํ์ด
- ๊ฑฐ๋ฆฌ๋๊ธฐ ๋ฌธ์ ๋ฅผ ์ฒ์ ๋ดค์ ๋๋
- ์์ญ ๊ตฌ๋ถํด์ ๊ฒ์ฌํ ์ ๋ค ๊ณจ๋ผ๋ด๊ณ ,
- ์ ๋ค๋ผ๋ฆฌ ๊ฑฐ๋ฆฌ ๊ณ์ฐํ๊ณ ,
- ์ธ์ ์ด๋ฉด ๊ธธ์ฐพ๊ธฐํ๊ณ
- ๋ง ๊ทธ๋ฐ... ๋ณต์กํ ์๊ฐ์ ํ๋๋ฐ,
- ํ๋ค๋ณด๋๊น ๊ทธ๋ฅ ๋ฌธ์์ด๋ก ๋น๊ตํ๋ฉด ๋์์?
- ์ถ์ด์ 2์ค for๋ฌธ 3๋ฒ์ผ๋ก ํต๊ณผ
- ๋ฒํฐ์ปฌ์ ๋ฐฐ์ด์ 90๋ ํ์ ์์ผ์ ํด๊ฒฐ...
- ๋ฐ์ค๋ ๊ทธ๋ฅ ๋ ธ๊ฐ๋ค๋ก... ใ ก.ใ ก;
def solution(places):
answer = [1] * 5
h_check_patterns = ["PP", "POP"]
v_checks_patterns = ["PP", "POP"]
box_checks_patterns = [("PO","OP"),("PX","OP"),("PO","XP"),("OP","PO"),("XP","PO"),("OP","PX")]
places_90d_r = []
for i in range(5):
for j in range(5):
if answer[i] == 0:
break
for h_chk in h_check_patterns:
if h_chk in places[i][j]:
answer[i] = 0
break
for i in range(5):
_tmp = []
for j in range(5):
_t = ""
for k in range(5):
_t += places[i][k][j]
_tmp.append(_t)
places_90d_r.append(_tmp)
for i in range(5):
for j in range(5):
if answer[i] == 0:
break
for h_chk in h_check_patterns:
if h_chk in places_90d_r[i][j]:
answer[i] = 0
break
for i in range(5):
for j in range(4):
if answer[i] == 0:
break
for k in range(4):
for b_chk in box_checks_patterns:
if places[i][j][k]+places[i][j][k+1] == b_chk[0] and places[i][j+1][k]+places[i][j+1][k+1] == b_chk[1]:
answer[i] = 0
break
return answer
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.21ms, 10.1MB)
ํ
์คํธ 2 ใ ํต๊ณผ (0.12ms, 10.4MB)
ํ
์คํธ 3 ใ ํต๊ณผ (0.09ms, 10.4MB)
ํ
์คํธ 4 ใ ํต๊ณผ (0.15ms, 10.4MB)
ํ
์คํธ 5 ใ ํต๊ณผ (0.05ms, 10.2MB)
ํ
์คํธ 6 ใ ํต๊ณผ (0.08ms, 10.3MB)
ํ
์คํธ 7 ใ ํต๊ณผ (0.10ms, 10.2MB)
ํ
์คํธ 8 ใ ํต๊ณผ (0.09ms, 10.3MB)
ํ
์คํธ 9 ใ ํต๊ณผ (0.06ms, 10.3MB)
ํ
์คํธ 10 ใ ํต๊ณผ (0.05ms, 10.3MB)
ํ
์คํธ 11 ใ ํต๊ณผ (0.09ms, 10.4MB)
ํ
์คํธ 12 ใ ํต๊ณผ (0.09ms, 10.2MB)
ํ
์คํธ 13 ใ ํต๊ณผ (0.10ms, 10.3MB)
ํ
์คํธ 14 ใ ํต๊ณผ (0.09ms, 10.2MB)
ํ
์คํธ 15 ใ ํต๊ณผ (0.08ms, 10.2MB)
ํ
์คํธ 16 ใ ํต๊ณผ (0.22ms, 10.3MB)
ํ
์คํธ 17 ใ ํต๊ณผ (0.63ms, 10.2MB)
ํ
์คํธ 18 ใ ํต๊ณผ (0.05ms, 10.4MB)
ํ
์คํธ 19 ใ ํต๊ณผ (0.10ms, 10.4MB)
ํ
์คํธ 20 ใ ํต๊ณผ (0.09ms, 10.3MB)
ํ
์คํธ 21 ใ ํต๊ณผ (0.05ms, 10.2MB)
ํ
์คํธ 22 ใ ํต๊ณผ (0.05ms, 10.4MB)
ํ
์คํธ 23 ใ ํต๊ณผ (0.21ms, 10.3MB)
ํ
์คํธ 24 ใ ํต๊ณผ (0.03ms, 10.4MB)
ํ
์คํธ 25 ใ ํต๊ณผ (0.22ms, 10.2MB)
ํ
์คํธ 26 ใ ํต๊ณผ (0.29ms, 10.4MB)
ํ
์คํธ 27 ใ ํต๊ณผ (0.10ms, 10.3MB)
ํ
์คํธ 28 ใ ํต๊ณผ (0.27ms, 10.2MB)
ํ
์คํธ 29 ใ ํต๊ณผ (0.21ms, 10.2MB)
ํ
์คํธ 30 ใ ํต๊ณผ (0.20ms, 10.3MB)
ํ
์คํธ 31 ใ ํต๊ณผ (0.15ms, 10.4MB)
- ๊ณ ์์ ํ์ด.
- ๋น์ทํ ๋ฐฉ์
def check(place):
for irow, row in enumerate(place):
for icol, cell in enumerate(row):
if cell != 'P':
continue
if irow != 4 and place[irow + 1][icol] == 'P':
return 0
if icol != 4 and place[irow][icol + 1] == 'P':
return 0
if irow < 3 and place[irow + 2][icol] == 'P' and place[irow + 1][icol] != 'X':
return 0
if icol < 3 and place[irow][icol + 2] == 'P' and place[irow][icol + 1] != 'X':
return 0
if irow != 4 and icol != 4 and place[irow + 1][icol + 1] == 'P' and (place[irow + 1][icol] != 'X' or place[irow][icol + 1] != 'X'):
return 0
if irow != 4 and icol != 0 and place[irow + 1][icol - 1] == 'P' and (place[irow + 1][icol] != 'X' or place[irow][icol - 1] != 'X'):
return 0
return 1
def solution(places):
return [check(place) for place in places]
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.05ms, 10.2MB)
ํ
์คํธ 2 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 3 ใ ํต๊ณผ (0.02ms, 10.4MB)
ํ
์คํธ 4 ใ ํต๊ณผ (0.03ms, 10.3MB)
ํ
์คํธ 5 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 6 ใ ํต๊ณผ (0.02ms, 10.1MB)
ํ
์คํธ 7 ใ ํต๊ณผ (0.02ms, 10.4MB)
ํ
์คํธ 8 ใ ํต๊ณผ (0.07ms, 10.2MB)
ํ
์คํธ 9 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 10 ใ ํต๊ณผ (0.01ms, 10.1MB)
ํ
์คํธ 11 ใ ํต๊ณผ (0.02ms, 10.4MB)
ํ
์คํธ 12 ใ ํต๊ณผ (0.01ms, 10.3MB)
ํ
์คํธ 13 ใ ํต๊ณผ (0.03ms, 10.4MB)
ํ
์คํธ 14 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 15 ใ ํต๊ณผ (0.02ms, 10.3MB)
ํ
์คํธ 16 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 17 ใ ํต๊ณผ (0.03ms, 10.3MB)
ํ
์คํธ 18 ใ ํต๊ณผ (0.01ms, 10.4MB)
ํ
์คํธ 19 ใ ํต๊ณผ (0.01ms, 10.3MB)
ํ
์คํธ 20 ใ ํต๊ณผ (0.02ms, 10.3MB)
ํ
์คํธ 21 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 22 ใ ํต๊ณผ (0.02ms, 10.4MB)
ํ
์คํธ 23 ใ ํต๊ณผ (0.01ms, 10.4MB)
ํ
์คํธ 24 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 25 ใ ํต๊ณผ (0.01ms, 10.2MB)
ํ
์คํธ 26 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 27 ใ ํต๊ณผ (0.03ms, 10.1MB)
ํ
์คํธ 28 ใ ํต๊ณผ (0.04ms, 10.2MB)
ํ
์คํธ 29 ใ ํต๊ณผ (0.02ms, 10.4MB)
ํ
์คํธ 30 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 31 ใ ํต๊ณผ (0.01ms, 10.2MB)
- ๋ ๋ค๋ฅธ ๊ณ ์์ ํ์ด
- ์ฌ๊ทํธ์ถ ๊ธธ์ฐพ๊ธฐ
def solution(places):
result = []
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
def f(i, j, cnt):
nonlocal good
if cnt >2 : return
if -1<i<5 and -1<j<5:
if graph[i][j] == 'X':
return
if cnt != 0 and graph[i][j] == 'P':
good = 0
return
graph[i][j] = 'X'
for w in range(4):
ni = i+dx[w]
nj = j+dy[w]
f(ni, nj, cnt+1)
for case in places:
graph = [list(r) for r in case]
good = 1
for i in range(5):
for j in range(5):
if graph[i][j]=='P':
f(i,j,0)
result.append(good)
return result
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.20ms, 10.4MB)
ํ
์คํธ 2 ใ ํต๊ณผ (0.08ms, 10.3MB)
ํ
์คํธ 3 ใ ํต๊ณผ (0.11ms, 10.4MB)
ํ
์คํธ 4 ใ ํต๊ณผ (0.09ms, 10.2MB)
ํ
์คํธ 5 ใ ํต๊ณผ (0.11ms, 10.2MB)
ํ
์คํธ 6 ใ ํต๊ณผ (0.20ms, 10.2MB)
ํ
์คํธ 7 ใ ํต๊ณผ (0.20ms, 10.2MB)
ํ
์คํธ 8 ใ ํต๊ณผ (0.15ms, 10.2MB)
ํ
์คํธ 9 ใ ํต๊ณผ (0.17ms, 10.3MB)
ํ
์คํธ 10 ใ ํต๊ณผ (0.17ms, 10.2MB)
ํ
์คํธ 11 ใ ํต๊ณผ (0.16ms, 10.3MB)
ํ
์คํธ 12 ใ ํต๊ณผ (0.14ms, 10.3MB)
ํ
์คํธ 13 ใ ํต๊ณผ (0.25ms, 10.2MB)
ํ
์คํธ 14 ใ ํต๊ณผ (0.12ms, 10.1MB)
ํ
์คํธ 15 ใ ํต๊ณผ (0.10ms, 10.3MB)
ํ
์คํธ 16 ใ ํต๊ณผ (0.06ms, 10.4MB)
ํ
์คํธ 17 ใ ํต๊ณผ (0.12ms, 10.1MB)
ํ
์คํธ 18 ใ ํต๊ณผ (0.15ms, 10.2MB)
ํ
์คํธ 19 ใ ํต๊ณผ (0.13ms, 10.4MB)
ํ
์คํธ 20 ใ ํต๊ณผ (0.09ms, 10.2MB)
ํ
์คํธ 21 ใ ํต๊ณผ (0.09ms, 10.4MB)
ํ
์คํธ 22 ใ ํต๊ณผ (0.09ms, 10.2MB)
ํ
์คํธ 23 ใ ํต๊ณผ (0.02ms, 10.2MB)
ํ
์คํธ 24 ใ ํต๊ณผ (0.23ms, 10.2MB)
ํ
์คํธ 25 ใ ํต๊ณผ (0.04ms, 10.3MB)
ํ
์คํธ 26 ใ ํต๊ณผ (0.04ms, 10.1MB)
ํ
์คํธ 27 ใ ํต๊ณผ (0.08ms, 10.2MB)
ํ
์คํธ 28 ใ ํต๊ณผ (0.09ms, 10.2MB)
ํ
์คํธ 29 ใ ํต๊ณผ (0.10ms, 10.1MB)
ํ
์คํธ 30 ใ ํต๊ณผ (0.05ms, 10.3MB)
ํ
์คํธ 31 ใ ํต๊ณผ (0.13ms, 10.3MB)
- ์ฝ์งํ๋ ๊ธฐ๋ก...
- ํญ์ 2D๋ก ๊ทธ๋ฆฌ๋ ๋ฒ๋ฆ์ด ์๋๋ฐ ๊ณ ์ณ์ผ ํ ๋ฏ
def solution(places):
answer = [0] * 5
people = []
rooms = [[[0 for _ in range(5)] for _ in range(5)] for _ in range(5)]
checks = (((-1,0),(-1,0)),((-1,0),(0,1)),((0,1),(-1,0)),((0,1),(0,1)),((0,1),(1,0)),((1,0),(0,1)),((1,0),(1,0)),((1,0),(0,-1)),((0,-1),(1,0)),((0,-1),(0,-1)),((0,-1),(1,0)),((1,0),(0,-1)))
def check_around(ri, yi, xi):
for chk in checks:
for y,x in chk:
if yi+y < 0:
continue
if xi+x < 0:
continue
if yi+y > 4:
continue
if yi+y > 4:
continue
if places[ri][yi+y][xi+x] == "P":
print(ri, yi+y,xi+x,"์ฌ๋์๋ค")
return False
return True
next_room = 0
for ri, room in enumerate(places):
print(ri, next_room)
if ri == next_room:
for yi in range(5):
for xi in range(5):
if "P" == places[ri][yi][xi]:
if check_around(ri, yi, xi) == False:
answer[ri] = 0
next_room += 1
break
if ri != next_room:
break
print(rooms)
return answer
def solution(places):
answer = [0] * 5
people = []
๋๊ธฐ์ค = [[[0 for _ in range(5)] for _ in range(5)] for _ in range(5)]
for ri, room in enumerate(places):
for yi in range(5):
for xi in range(5):
# ๋๊ธฐ์ค[ri][yi][xi] = places[ri][yi][xi]
if "P" == places[ri][yi][xi]:
people.append((ri, yi, xi))
def dfs(ri, yi, xi, cnt):
cnt -= 1
if cnt == 0:
return True
if places[ri][yi][xi] == "P":
return False
elif places[ri][yi][xi] == "O":
๋๊ธฐ์ค[ri][yi][xi] = 1
if cnt == 0:
return True
else:
if yi + 1 < 5:
if dfs(ri, yi+1, xi, cnt) == False:
return False
if xi + 1 < 5:
if dfs(ri, yi, xi+1, cnt) == False:
return False
if yi > 0:
if dfs(ri, yi-1, xi, cnt) == False:
return False
if xi > 0:
if dfs(ri, yi, xi-1, cnt) == False:
return False
return True
def draw_room(ri):
print("๋ฃธ:",ri)
for y in range(5):
for x in range(5):
print(๋๊ธฐ์ค[ri][y][x],end=" ")
print("")
print("="*10)
next_room = 0
for ri, yi, xi in people:
answer[ri] = 1
if next_room == ri:
if dfs(ri, yi, xi, 2) == False:
answer[ri] = 0
next_room += 1
if next_room == 5:
break
draw_room(ri)
#print(๋๊ธฐ์ค)
return answer
def solution(places):
answer = [0] * 5
area_of_places = []
man_of_places = []
cnt_of_area = 0
area_set = {0:0}
for ri,r in enumerate(places):
_tmp = []
for yi,y in enumerate(r):
_t = list(y.replace("P","O"))
for xi in range(5):
if places[ri][yi][xi] == "P":
man_of_places.append([ri, yi, xi, 0]) # Room, Y์ขํ, X์ขํ, ๊ฐ์ผ์ฌ๋ถ
_tmp.append(_t)
area_of_places.append(_tmp)
def dfs(r,y,x):
area_of_places[r][y][x] = cnt_of_area
if 0<x and area_of_places[r][y][x-1] == "O":
dfs(r,y,x-1)
if 0<y and area_of_places[r][y-1][x] == "O":
dfs(r,y-1,x)
if x<4 and area_of_places[r][y][x+1] == "O":
dfs(r,y,x+1)
if y<4 and area_of_places[r][y+1][x] == "O":
dfs(r,y+1,x)
return
for ri,r in enumerate(places):
for yi in range(5):
for xi in range(5):
if area_of_places[ri][yi][xi] == "O":
dfs(ri,yi,xi)
cnt_of_area += 1
for i,(r,y,x,m) in enumerate(man_of_places):
man_of_places[i][3] = area_of_places[r][y][x]
try:
area_set[man_of_places[i][3]] += 1
except:
area_set[man_of_places[i][3]] = 1
for k, v in list(area_set.items()):
if v <= 1:
del area_set[k]
for i in reversed(range(len(man_of_places))):
if man_of_places[i][3] not in area_set:
man_of_places.pop(i)
man_of_places.sort(key=lambda x:x[3])
print(man_of_places)
print(area_set)
# for ri,r in enumerate(area_of_places):
# for yi,y in enumerate(r):
# for xi,x in enumerate(y):
# print(area_of_places[ri][yi][xi],end=" ")
# print("")
# print("="*10)
# answer[0] = 1
return answer
- ์๊ฐํด๋ณด๋ ํ์ด ๋ฐฉ๋ฒ์ด ์ฌ๋ฌ๊ฐ์ง๋ก ํด๊ฒฐํ ์ ์๋ ๋ฌธ์ ๊ฐ ๋ณ๋ณ๋ ฅ์ด ๋ ๋์ ๋ฏ ํ๋ค.
- ๊ทธ๋ฌ๋ฉด ๋์ฒ๋ผ ๋ ธ๊ฐ๋ค๋ก ํธ๋ ๋ฌด์ง์ฑ ์ฝ๋๋ค์ ๋ค... ใ .ใ
- 90๋ ํ์ ์ ๋ง์ง๋ง์ ๋ฃ๋ ๊ฒ๋ ๊ด์ฐฎ์ง ์๋ ์ถ์๋๋ฐ 5x5ํฌ๊ธฐ๋ผ ๋ณ ์ฐจ์ด ์๋ค.
def solution(places):
answer = [1] * 5
h_check_patterns = ["PP", "POP"]
v_checks_patterns = ["PP", "POP"]
box_checks_patterns = [("PO","OP"),("PX","OP"),("PO","XP"),("OP","PO"),("XP","PO"),("OP","PX")]
places_90d_r = []
for i in range(5):
for j in range(5):
if answer[i] == 0:
break
for h_chk in h_check_patterns:
if h_chk in places[i][j]:
answer[i] = 0
break
for i in range(5):
for j in range(4):
if answer[i] == 0:
break
for k in range(4):
for b_chk in box_checks_patterns:
if places[i][j][k]+places[i][j][k+1] == b_chk[0] and places[i][j+1][k]+places[i][j+1][k+1] == b_chk[1]:
answer[i] = 0
break
for i in range(5):
_tmp = []
for j in range(5):
if answer[i] == 0:
break
_t = ""
for k in range(5):
_t += places[i][k][j]
_tmp.append(_t)
places_90d_r.append(_tmp)
for i in range(5):
for j in range(5):
if answer[i] == 0:
break
for h_chk in h_check_patterns:
if h_chk in places_90d_r[i][j]:
answer[i] = 0
break
return answer
์ ํ์ฑ ํ
์คํธ
ํ
์คํธ 1 ใ ํต๊ณผ (0.12ms, 10.3MB)
ํ
์คํธ 2 ใ ํต๊ณผ (0.22ms, 10.2MB)
ํ
์คํธ 3 ใ ํต๊ณผ (0.13ms, 10.2MB)
ํ
์คํธ 4 ใ ํต๊ณผ (0.11ms, 10.2MB)
ํ
์คํธ 5 ใ ํต๊ณผ (0.08ms, 10.2MB)
ํ
์คํธ 6 ใ ํต๊ณผ (0.09ms, 10.3MB)
ํ
์คํธ 7 ใ ํต๊ณผ (0.06ms, 10.4MB)
ํ
์คํธ 8 ใ ํต๊ณผ (0.10ms, 10.4MB)
ํ
์คํธ 9 ใ ํต๊ณผ (0.07ms, 10.3MB)
ํ
์คํธ 10 ใ ํต๊ณผ (0.04ms, 10.4MB)
ํ
์คํธ 11 ใ ํต๊ณผ (0.20ms, 10.4MB)
ํ
์คํธ 12 ใ ํต๊ณผ (0.05ms, 10.2MB)
ํ
์คํธ 13 ใ ํต๊ณผ (0.06ms, 10.2MB)
ํ
์คํธ 14 ใ ํต๊ณผ (0.11ms, 10.4MB)
ํ
์คํธ 15 ใ ํต๊ณผ (0.14ms, 10.4MB)
ํ
์คํธ 16 ใ ํต๊ณผ (0.13ms, 10.3MB)
ํ
์คํธ 17 ใ ํต๊ณผ (0.09ms, 10.2MB)
ํ
์คํธ 18 ใ ํต๊ณผ (0.04ms, 10.2MB)
ํ
์คํธ 19 ใ ํต๊ณผ (0.07ms, 10.2MB)
ํ
์คํธ 20 ใ ํต๊ณผ (0.07ms, 10.4MB)