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

19084번 - One Step Closer 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB422100.000%

문제

Consider a table of size $n \times m$ consisting of characters "+" and "-". A single operation with the table is to choose a cell and invert all characters in its row and column simultaneously (the cell itself is also inverted). Inverting a character means replacing "+" by "-" and vice versa.

Vasya wants to fill all cells with "-". To achieve that, he uses the following algorithm:

  • If all cells are "-", end the algorithm.
  • Otherwise, remember the current positions of "+". Assume they are $(r_1, c_1),ドル $(r_2, c_2),ドル $\ldots,ドル $(r_k, c_k)$. After that, he performs one operation for each cell $(r_i, c_i)$ and proceeds to step 1.

Sasha is interested whether Vasya can reach his goal. If this is the case, he wants to know the total number of operations Vasya will perform before he stops.

입력

The first line of input contains three integers $n,ドル $m$ and $q$ (1ドル \le n, m \le 10^5,ドル 0ドル \le q \le 10^5$).

Then follows the description of the initial configuration which looks as follows. The $i$-th of the next $q$ lines contains four integers $x_{i,1},ドル $y_{i,1},ドル $x_{i,2}$ and $y_{i,2}$ (1ドル\le x_{i,1} \le x_{i,2} \le n,ドル 1ドル \le y_{i,1} \le y_{i,2} \le m$). They define a rectangle containing all such cells $(x, y)$ that $x_{i,1} \le x \le x_{i,2}$ and $y_{i,1} \le y \le y_{i,2}$. A cell $(x, y)$ is initially "+" if and only if it is contained in an odd number of rectangles.

See Notes section for further explanation.

출력

If Vasya will never finish performing operations, print "-1". Otherwise, print the number of operations he will perform.

제한

예제 입력 1

3 3 2
1 1 2 2
2 2 3 3

예제 출력 1

6

예제 입력 2

3 3 2
1 2 1 3
2 1 3 1

예제 출력 2

-1

힌트

In the first example, the board initially looks as follows:

++-
+-+
-++

After the only iteration of the algorithm, which consists of six operations, the board is filled with ``\texttt{-}''.

In the second example, the board looks as follows and stays the same after each iteration of the algorithm:

-++
+--
+--

출처

Camp > Petrozavodsk Programming Camp > Summer 2017 > Day 5: Moscow IPT Contest H번

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

출처

대학교 대회

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

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