🔻PS/Codetree
[Codetree] 격자 위의 편안한 상태 Python
_니지
2024. 8. 6. 11:03
https://www.codetree.ai/missions/5/problems/comfortable-state-on-the-grid/description
코드트리 | 코딩테스트 준비를 위한 알고리즘 정석
국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.
www.codetree.ai
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
graph = [[0 for _ in range(n)] for _ in range(n)]
def isConfortable(x, y):
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
cnt = 0
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0<= nx and nx <n and 0<= ny and ny <n:
if graph[nx][ny] == 1:
cnt += 1
if cnt == 3:
return 1
else:
return 0
for i in range(m):
x, y = map(int, input().split())
x -= 1
y -= 1
graph[x][y] = 1
print(isConfortable(x, y))
728x90
반응형