https://www.codetree.ai/missions/2/problems/number-of-happy-sequence/description
import sys
input = sys.stdin.readline
n, m = map(int, input().split(" "))
# happy = 0
happy = []
graph = []
for _ in range(n):
temp = list(map(int, input().rstrip().split(" ")))
graph.append(temp)
t_graph = list(map(list, zip(*graph)))
if m == 1:
print(2*n)
else:
for row in graph:
for i in range(n-m+1):
cnt = 0
for k in range(i, i+m-1):
if row[k] == row[k+1]:
cnt += 1
if cnt+1 == m:
happy.append(row)
continue
for row in t_graph:
for i in range(n-m+1): #열의 범위
cnt = 0
for k in range(i, i+m-1): # 열의 범위 내에서 움직이기
if row[k] == row[k+1]:
cnt += 1
if cnt+1 == m:
happy.append(row)
continue
print(len(list(set(tuple(h) for h in happy))))
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 삼각형 컨베이어 벨트 Python (0) | 2024.07.27 |
---|---|
[Codetree] 컨베이어 벨트 Python (0) | 2024.07.27 |
[Codetree] 최고의 33위치 Python (1) | 2024.07.23 |
[Codetree] 뿌요뿌요 Python (0) | 2024.07.19 |
[Codetree] 안전 지대 Python (0) | 2024.07.19 |