본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬] 18156번 Black and White

by 현장 2024. 8. 31.

-Code

n = int(input())
arr = [input() for _ in range(n)]
res = 1

for x in range(n):
    line = arr[x]

    if line.count('B') > n // 2 or line.count('W') > n // 2:
        res = 0

    if 'BBB' in line or 'WWW' in line:
        res = 0

if res == 1:
    for x in range(n):
        line = ""
        for y in range(n):
            line += arr[y][x]

        if line.count('B') > n // 2 or line.count('W') > n // 2:
            res = 0

        if 'BBB' in line or 'WWW' in line:
            res = 0
print(res)