ZIO12003 - Editorial

ZIO 2012 Problem 3

Editorialist : Sudheera Y S

Problem Link : ZIO 2012 Problem 3

Prerequisites : Logic

Problem statement :

There is a grid given and each cell contains a number. We can move from cell x to cell y if they both are in the SAME ROW or SAME COLUMN and the number written in cell y is strictly less than the number written in the cell x . We want to color some cells red so that :

β€’ Every cell can be reached by starting at a red cell and following a sequence of ZERO or MORE moves as defined above.

β€’ The number of red cells is as small as possible

You should report the following information:

β€’ The number of red cells.

β€’ The smallest number appearing amongst all red cells.

Quick Explanation :

Let us consider a cell. It will be reachable from another cell ( which is in the same row or same column ) if there is a cell ( in the same row and column ) which is strictly more than that

But if the cell is the maximum value in the row or column , we have to colour it red so that it is reachable.

For every row and column , find the maximum value , and colour all the values which are equal to the maximum value ( because if two cells have the same maximum value , both of them should be coloured red )

Subtask A :

Grid :

Maximum in

Row 1 β†’ 55

Row 2 β†’ 59

Row 3 β†’ 59

Row 4 β†’ 40

Row 5 β†’ 55

Row 6 β†’ 54

Row 7 β†’ 40

Row 8 β†’ 59

Maximum in

Column 1 β†’ 55

Column 2 β†’ 54

Column 3 β†’ 55

Column 4 β†’ 59

Column 5 β†’ 59

Column 6 β†’ 40

Column 7 β†’ 55

Now let us consider the row maximum one by one and make sure the column maximum is not greater than the value. If it is greater than the value , then we need not colour it though it is the maximum in the row because there is another maximum in the column.

Row 1 β†’

Maximum : 55

Occurs at columns 1,5,7

Column 1 max = 55 , we need to colour this cell red

Column 5 max = 59 , we need not colour this cell

Column 7 max = 55 , we need to colour this cell red

Row 2 β†’

Maximum : 59

Occurs at column 4

Column 4 max = 59 , we need to colour this cell red

Row 3 β†’

Maximum : 59

Occurs at column 5

Column 5 max = 59 , we need to colour this cell red

Row 4 β†’

Maximum : 40

Occurs at columns 4,6,7

Column 4 max = 59 , we need not colour this cell

Column 6 max = 40 , we need to colour this cell red

Column 7 max = 55 , we need not colour this cell

Row 5 β†’

Maximum : 55

Occurs at columns 1,3

Column 1 max = 55 , we need to colour this cell red

Column 3 max = 55 , we need to colour this cell red

Row 6 β†’

Maximum : 54

Occurs at column 7

Column 7 max = 55 , we need not colour this cell

Row 7 β†’

Maximum : 40

Occurs at columns 1,6

Column 1 max = 55 , we need not colour this cell

Column 6 max = 40 , we need to colour this cell red

Row 8 β†’

Maximum : 59

Occurs at column 4

Column 4 max = 59 , we need to colour this cell red

Now we are done with seeing all the maximum cells. Totally we coloured 9 cells and the minimum among them is 40

Our grid looks like this after colouring :

Answer : 9,40

Subtask B , C : Bonus :slight_smile:

Hope you understood

:slight_smile:

8 Likes

we can always prove that an element (i,j) should be painted red iff it is the maximum in the row and column ,in this way we can calculate the answer without recursion.

4 Likes

Thanks. Edited my very long solution. :slight_smile:


@sudheerays123
I think that the cells in yellow should also be coloured as they don’t have any neighbours that are strictly greater than it.

Do correct me if I’m wrong :sweat_smile:

For example ,

You say we have to colour 40 at (7,1)
But for that in the 1 column , there is 55 > 40

Therefore 40 will be reachable if we colour 55 in the first column

But to reach 41 we have to go through either 10 or 22 or 21 all of which are not allowed.

Hey Aviral,

Problem states : We can move from cell x to cell y if they both are in the SAME ROW or SAME COLUMN and the number written in cell y is strictly less than the number written in the cell x .

It does not mean only neighbors!

eg : 52 at (5,5) may be greater than all of its neighbors(10,21,22), but it has 55 in its row and 59 in its column both of which are greater than 52, thus we can reach 52 from 59 or 55, so we need not color it red.

Same implies for every number you colored in yellow.

Hope this clears your doubt!

And thanks to @sudheerays123 for the great editorial!