https://www.codetree.ai/missions/5/problems/comfortable-state-on-the-grid/description
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
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 빙빙 돌며 사각형 채우기 Python (0) | 2024.08.06 |
---|---|
[Codetree] 빙빙 돌며 숫자 사각형 채우기 2 Python (0) | 2024.08.06 |
[Codetree] 이상한 진수 2 Python (0) | 2024.08.06 |
[Codetree] 최고의 13위치 Python (0) | 2024.08.05 |
[Codetree] 일렬로 서있는 소 2 Python (0) | 2024.08.04 |