Digital Art
Time limit1sMemory limit1024 MB
Given an H by W grid of color numbers, cover one rectangle of at most S pixels to minimize the number of distinct colors still visible.
- Level
Hard8 of 10
- Topics
- Sliding window, Two pointers, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
Aoi, a student at JOI High School, makes digital art as a hobby, and today she made a new image.
The image is H pixels tall and W pixels wide, represented as an H × W grid. The pixel in the i-th row from the top (1 ≦ i ≦ H) and the j-th column from the left (1 ≦ j ≦ W) is written (i, j). Each pixel is painted with one color. Each color has a number from 1 to 256, and the color number of pixel (i, j) is Ai, j.
Aoi showed this image to her classmate Rin, but Rin did not like it, saying "the image uses too many colors." So Aoi wondered whether she could cover some region of the image as follows to make the number of visible colors as small as possible.
- Aoi chooses at most
Spixels and covers them. - The region of covered pixels must be a single rectangle.
Given the image data and the upper bound S on the number of covered pixels, write a program to find the minimum possible number of visible colors when some region of the image is covered.
Input
The input is given from standard input in the following format.
H W S
A1, 1 A1, 2 … A1, W
A2, 1 A2, 2 … A2, W
:
AH, 1 AH, 2 … AH, W
Output
On standard output, print in one line the minimum possible number of visible colors when some region of the image is covered.
In particular, if it is possible to make no pixel visible, print 0.
Constraints
1 ≦ H ≦ 1 000.1 ≦ W ≦ 1 000.1 ≦ S ≦ HW.1 ≦ Ai, j ≦ 256(1 ≦ i ≦ H,1 ≦ j ≦ W).- All given values are integers.