https://www.codetree.ai/missions/5/problems/place-more-than-3-ones/description
import sys
input = sys.stdin.readline
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
n = int(input())
graph = []
for _ in range(n):
temp = list(map(int, input().rstrip().split(" ")))
graph.append(temp)
result = 0
for i in range(n):
for j in range(n):
cnt = 0
for k in range(4):
nx = i + dx[k]
ny = j + dy[k]
if 0 <= nx and nx <n and 0<= ny and ny < n:
if graph[nx][ny] == 1:
cnt += 1
if cnt >= 3:
result += 1
print(result)
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 빙빙 돌며 숫자 사각형 채우기 Python (0) | 2024.07.29 |
---|---|
[Codetree] 작은 구슬의 이동 Python (0) | 2024.07.29 |
[Codetree] 문자에 따른 명령 2 Python (0) | 2024.07.29 |
[Codetree] 방향에 맞춰 이동 Python (0) | 2024.07.29 |
[Codetree] 1차원 젠가 Python (0) | 2024.07.28 |