Logo
(追記) (追記ここまで)

32821번 - Diagonal Flipping 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB205846541.401%

문제

We are given an $m \times n$ grid that consists of 0ドル$s and 1ドル$s. We have two types of diagonal operations like the following two figures. The type $A$ diagonal flipping operation to a grid position $(i,j)$ is to flip all the elements in the positions $(i + k,j - k)$ of the grid for any integer $k$. If we flip the element 0ドル,ドル then it becomes 1ドル$. If we flip the element 1ドル,ドル then it becomes 0ドル$. The type $B$ diagonal flipping operation to a grid position $(i,j)$ is to flip all the elements in the positions $(i + k,j + k)$ of the grid for any integer $k$. Note that a grid position $(p, q)$ is valid only when 0ドル ≤ p ≤ m - 1,ドル 0ドル ≤ q ≤ n - 1$.

Fig 1. Type $A$ diagonal operation to the grid position $(2, 0)$

Fig 2. Type $B$ diagonal operation to the grid position $(2, 1)$

Fig 1 shows the type $A$ diagonal flipping operation to the grid position $(2, 0)$. Note that the type $A$ diagonal flipping operations to the grid positions $(1, 1)$ or $(0, 2)$ have the same effect. Fig 2 shows the type $B$ diagonal flipping operation to the grid position $(2, 1)$. The type $B$ diagonal flipping operations to the grid positions $(1, 0)$ or $(3, 2)$ have the same effect.

Given an information of an $m \times n$ grid, write a program to output the minimum number of the diagonal operations to make all the elements in the grid to zeros.

입력

Your program is to read from standard input. The first line of input contains two positive integers $m$ (1ドル ≤ m≤1,000円$) and $n$ (1ドル ≤ n ≤ 1,000円$) where $m$ and $n$ indicate the number of rows and columns of the grid, respectively. The rows of the grid are numbered from 0ドル$ to $m - 1$ and the columns are numbered from 0ドル$ to $n - 1$. In the following $m$ lines, the $i$-th line contains $n$ numbers, separated by spaces, which are zero or one that correspond to the row $i - 1$ of the grid.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the minimum number of the diagonal operations to make all the elements of the grid to zeros. If it is not possible to make all the elements of the grid zeros, the program should print the number -1.

제한

예제 입력 1

4 3
1 0 1
0 0 1
1 1 1
0 0 0

예제 출력 1

4

예제 입력 2

2 2
1 1
1 1

예제 출력 2

2

예제 입력 3

3 3
1 0 1
0 1 0
1 0 1

예제 출력 3

3

예제 입력 4

3 3
0 0 1
0 0 1
1 0 1

예제 출력 4

-1

힌트

출처

ICPC > Regionals > Asia Pacific > Korea > Nationwide Internet Competition > Seoul Nationalwide Internet Competition 2024 D번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /