문제 확인하기
2. 정답 코드 (Python, memory: 31256KB, time: 48ms)
import sys
input = sys.stdin.readline
def count_segments(matrix, N):
count = 0
for i in range(N):
cnt = 0
for j in range(N):
if matrix[i][j] == '.':
cnt += 1
elif matrix[i][j] == 'X':
if cnt >= 2:
count += 1
cnt = 0
if cnt >= 2:
count += 1
return count
N = int(input())
matrix = [list(map(str, input().strip())) for _ in range(N)]
row = count_segments(matrix, N)
matrix_transposed = [[matrix[j][i] for j in range(N)] for i in range(N)]
column = count_segments(matrix_transposed, N)
print(row, column)