문제 확인하기
2. 정답 코드 (python3, memory: 31120KB, time: 52ms)
rows, columns = map(int, input().split(' '))
grid = []
for _ in range(rows):
row_data = list(map(str, input()))
grid.append(row_data)
monster_patterns = []
for i in range(rows-1):
for j in range(columns-1):
monster_patterns.append([grid[i][j], grid[i][j+1], grid[i+1][j], grid[i+1][j+1]])
result_counts = [0 for _ in range(5)]
for pattern in monster_patterns:
if '#' in pattern:
continue
elif pattern.count('.') == 4:
result_counts[0] += 1
elif pattern.count('X') == 1:
result_counts[1] += 1
elif pattern.count('X') == 2:
result_counts[2] += 1
elif pattern.count('X') == 3:
result_counts[3] += 1
elif pattern.count('X') == 4:
result_counts[4] += 1
for count in result_counts:
print(count)