끝에서부터 1나오면 뒤집어주면 됩니다.
import sys
input = sys.stdin.readline
def xor(a, b):
for row in range(a + 1):
for col in range(b + 1):
matrix[row][col] ^= 1
n, m = map(int, input().split())
matrix = [list(map(int, list(input().rstrip()))) for __ in range(n)]
cnt = 0
for row in range(n - 1, -1, -1):
for col in range(m - 1, -1, -1):
if matrix[row][col]:
cnt += 1
xor(row, col)
print(cnt)
'practivceAlgorithm > 백준' 카테고리의 다른 글
[백준][Python] 20159 동작 그만. 밑장 빼기냐? (0) | 2021.10.07 |
---|---|
[백준][Python] 1890 점프 (0) | 2021.10.06 |
[백준][Python] 18185 라면 사기(small) (2) | 2021.10.06 |
[백준][Python] 18186 라면 사기(Large) (0) | 2021.10.06 |
[백준][Python] 17135 캐슬디펜스 (0) | 2021.10.06 |