λ°μν
π€λ¬Έμ ν΄κ²°
-
S1 | μμ νμ
Nμ λ²μκ° λ§€μ° μμΌλ―λ‘ μμ νμμ νλ λ¬Έμ μ΄λ€.
λ²½μ μΈμΈ μ μλ λΉ κ³΅κ°μ 리μ€νΈλ‘ ꡬνκ³ ,
μ½€λΉλ€μ΄μ (3)μ νλ€. ( λ²½μ 3κ° μΈμμΌ νλ―λ‘ )
λ²½μ μΈμ°λ©΄ κ°μλ₯Ό μμνλ€.
μ μλ리μ€νΈλ λ§λ€μ΄μ μνμ’μ° κ°μλ₯Ό νλ€.
κ°μλ₯Ό νλ λμ€ λκΉμ§ κ°κ±°λ λ²½μ λ§λλ©΄ ν΄λΉ λ°©ν₯μ κ°μλ λ©μΆκ³
νμμ λ§λλ©΄ κ°μμ μ±κ³΅νλ―λ‘
κ·Έ λ²½μ λ€μ μ² κ±°νκ³ λ€λ₯Έ λ²½μ μΈμ΄λ€.
μ μλμ΄ λͺ¨λ λ°©ν₯μ λν΄μ κ°μμ μ€ν¨ν λκΉμ§ λ°λ³΅νλ€.
π»μμ€ μ½λ
from itertools import combinations as cb
def watch():
for teacher in teacher_list:
x, y = teacher
# μ
nx, ny = x, y
while nx > 0:
nx -= 1
if hallway[nx][ny] == 'S':
return False
if hallway[nx][ny] == 'O':
break
# ν
nx, ny = x, y
while nx < N - 1:
nx += 1
if hallway[nx][ny] == 'S':
return False
if hallway[nx][ny] == 'O':
break
# μ’
nx, ny = x, y
while ny > 0:
ny -= 1
if hallway[nx][ny] == 'S':
return False
if hallway[nx][ny] == 'O':
break
# μ°
nx, ny = x, y
while ny < N - 1:
ny += 1
if hallway[nx][ny] == 'S':
return False
if hallway[nx][ny] == 'O':
break
return True
if __name__ == '__main__':
N = int(input())
hallway = [input().split() for _ in range(N)]
empty_list = []
teacher_list = []
for i in range(N):
for j in range(N):
if hallway[i][j] == 'X':
empty_list.append((i, j))
elif hallway[i][j] == 'T':
teacher_list.append((i, j))
# λ²½ 3κ° λ½κΈ°
for walls in cb(empty_list, 3):
# λ²½ μΈμ°κΈ°
for wall in walls:
x, y = wall
hallway[x][y] = 'O'
# κ°μνκΈ°
if watch():
print('YES')
break
# λ²½ νλ¬ΌκΈ°
for wall in walls:
x, y = wall
hallway[x][y] = 'X'
else:
print('NO')
πλ¬Έμ νμΈ
μΆμ²: BACKJOON ONLINE JUDGE
λ§ν¬: https://www.acmicpc.net/problem/18428
λ°μν
'Algorithm Problem > Python' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[python] λ°±μ€ - 17140. μ΄μ°¨μ λ°°μ΄κ³Ό μ°μ° (2) | 2020.11.30 |
---|---|
[python] λ°±μ€ - 10819. μ°¨μ΄λ₯Ό μ΅λλ‘ (0) | 2020.11.29 |
[python] λ°±μ€ - 1916. μ΅μλΉμ© ꡬνκΈ° (0) | 2020.11.27 |
[python] λ°±μ€ - 2573. λΉμ° (0) | 2020.11.26 |
[python] λ°±μ€ - 2493. ν (0) | 2020.11.25 |