#K43942. Minimum Rectangular Grid for Unique Pixels

    ID: 27421 Type: Default 1000ms 256MiB

Minimum Rectangular Grid for Unique Pixels

Minimum Rectangular Grid for Unique Pixels

You are given an m x n grid where each cell contains an integer representing a pixel. The grid may contain duplicate values. Your task is to determine the minimum dimensions of a rectangular grid (with rows r and columns c) such that the total number of cells r × c is at least the number of unique pixel values in the input grid.

Formally, let \( U \) be the set of unique pixel values in the grid and \(|U|\) its cardinality. You need to find the smallest pair of positive integers \((r, c)\) such that:

[ r \times c \geq |U| ]

The solution increments either the number of rows or the number of columns until the rectangle can accommodate all unique pixels. This problem tests your ability to process grid input and implement a simple greedy strategy.

inputFormat

The first line of the input contains two integers m and n (the number of rows and columns of the grid, respectively). The following m lines each contain n integers representing the pixel values in that row.

outputFormat

Output a single line with two integers separated by a space, representing the minimal number of rows and columns (r and c) required so that \( r \times c \geq |U| \), where \(|U|\) is the number of unique pixel values.

## sample
3 3
1 2 3
4 5 6
7 8 9
3 3