bzoj#P4776. [USACO2017 Open] Modern Art
[USACO2017 Open] Modern Art
题目描述
Art critics worldwide have only recently begun to recognize the creative genius behind the great bovine painter, Picowso.
Picowso paints in a very particular way. She starts with an blank canvas, represented by an grid of zeros, where a zero indicates an empty cell of the canvas. She then draws rectangles on the canvas, one in each of colors (conveniently numbered ). For example, she might start by painting a rectangle in color , giving this intermediate canvas:
2 2 2 0
2 2 2 0
2 2 2 0
0 0 0 0
She might then paint a rectangle in color :
2 2 2 0
2 7 7 7
2 7 7 7
0 0 0 0
And then she might paint a small rectangle in color :
2 2 3 0
2 7 3 7
2 7 7 7
0 0 0 0
Each rectangle has sides parallel to the edges of the canvas, and a rectangle could be as large as the entire canvas or as small as a single cell. Each color from is used exactly once, although later colors might completely cover up some of the earlier colors.
Given the final state of the canvas, please count how many of the colors could have possibly been the first to be painted.
输入格式
The first line of input contains , the size of the canvas.
The next lines describe the final picture of the canvas, each containing integers that are in the range . The input is guaranteed to have been drawn as described above, by painting successive rectangles in different colors.
输出格式
Please output a count of the number of colors that could have been drawn first.
4
2 2 3 0
2 7 3 7
2 7 7 7
0 0 0 0
14
说明
In this example, color could have been the first to be painted. Color clearly had to have been painted after color , and color clearly had to have been painted after color . Since we don't see the other colors, we deduce that they also could have been painted first.
数据规模与约定
对于 的数据,。
题目来源
Platinum