DMOPC '20 Contest 4 P2 - Beautiful Grids

View as PDF

Submit solution


Points: 7 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Penelope is playing a game on an N×M grid! Her grid currently contains K 1s, while the rest of her grid cells contain 0s.

Penelope isn't sure she likes her grid though. Specifically, she is worried that her grid isn't beautiful. A grid is beautiful if every row sum and column sum are even.

Penelope is in a hurry to make her grid beautiful so she asks you: how can she make her grid beautiful? On each move, you can flip the value of a grid cell: from 1 to 0 or 0 to 1. Since she is in a hurry, she asks you to make her grid beautiful as fast as possible.

Constraints

1N,M1018

0Kmin(N×M,3×105)

1aiN

1biM

All cells given are distinct.

Subtask 1 [30%]

1N,M5000

Subtask 2 [70%]

No additional constraints.

Input Specification

The first line contains 3 integers, N, the number of rows; M, the number of columns; and K.

The next K lines each contain two integers ai and bi, indicating that the cell in the aith row, bith column contains a 1.

Output Specification

On the first line output A, the minimum number of moves required to make the grid beautiful. A must satisfy 0A106. It can be proven that the minimum A lies within this range.

On the next A lines, output two space-separated integers ai and bi, indicating that you will flip the cell in the aith row, bith column.

You may output any valid sequence.

Note: your output must follow the standard convention of not having any extra whitespace, and it must end with a new line.

Scoring

If you output an incorrect value A, but a valid sequence of moves, you will receive 10% for that test case.

If you output a correct value A, but an invalid sequence of moves, you will receive 20% for that test case.

If you output a correct value of A and any valid sequence of moves, you will receive 100% for that test case.

Your score for a subtask will be the minimum score across all test cases of that subtask.

Sample Input

Copy
2 3 3
1 1
1 3
2 1

Sample Output

Copy
1
2 3

Explanation

Note that after our operation, our grid is:

Copy
1 0 1
1 0 1

which satisfies the constraints.


Comments


  • -2
    gavin_chen  commented on Dec. 28, 2022, 8:33 p.m.

    can someone tell me why im getting presentation error? there shoudlnt be aqny extra whitespace


    • 0
      andy_zhu23  commented on Dec. 28, 2022, 10:33 p.m.

      I think for whatever value A you got, you didn't output A lines afterwards