CF1500D.Tiles for Bathroom

省选/NOI-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kostya is extremely busy: he is renovating his house! He needs to hand wallpaper, assemble furniture throw away trash.

Kostya is buying tiles for bathroom today. He is standing in front of a large square stand with tiles in a shop. The stand is a square of n×nn \times n cells, each cell of which contains a small tile with color ci, jc_{i,\,j}. The shop sells tiles in packs: more specifically, you can only buy a subsquare of the initial square.

A subsquare is any square part of the stand, i. e. any set S(i0,j0,k)=ci, j ∣ i0≤i<i0+k,j0≤j<j0+kS(i_0, j_0, k) = {c_{i,\,j}\ |\ i_0 \le i \lt i_0 + k, j_0 \le j \lt j_0 + k} with 1≤i0,j0≤n−k+11 \le i_0, j_0 \le n - k + 1.

Kostya still does not know how many tiles he needs, so he considers the subsquares of all possible sizes. He doesn't want his bathroom to be too colorful. Help Kostya to count for each k≤nk \le n the number of subsquares of size k×kk \times k that have at most qq different colors of tiles. Two subsquares are considered different if their location on the stand is different.

科斯佳非常忙:他正在装修自己的房子!他需要贴墙纸、组装家具、清理垃圾。

今天,科斯佳要为浴室购买瓷砖。他正站在一家商店里一个大型方形展架前。该展架是一个 n×nn \times n 的方格阵列,每个格子中都摆放着一块颜色为 ci, jc_{i,\,j} 的小瓷砖。商店仅以“子方阵”的形式出售瓷砖,即顾客只能购买原展架的一个子方阵。

所谓子方阵,是指展架中的任意一个正方形区域,即形如

S(i0,j0,k)={ci, j ∣ i0≤i<i0+k, j0≤j<j0+k}S(i_0, j_0, k) = \{c_{i,\,j}\ \mid\ i_0 \le i < i_0 + k,\ j_0 \le j < j_0 + k\}

的集合,其中 1≤i0,j0≤n−k+11 \le i_0, j_0 \le n - k + 1。

科斯佳尚不确定自己究竟需要多少瓷砖,因此他打算考虑所有可能尺寸的子方阵。他不希望浴室颜色过于繁杂。请帮助科斯佳统计:对每个 k≤nk \le n,有多少个 k×kk \times k 大小的子方阵至多包含 qq 种不同颜色的瓷砖。若两个子方阵在展架上的位置不同,则视为不同的子方阵。

输入格式

The first line contains two integers nn and qq (1≤n≤15001 \le n \le 1500, 1≤q≤101 \le q \le 10) — the size of the stand and the limit on the number of distinct colors in a subsquare.

Each of the next nn lines contains nn integers ci, jc_{i,\,j} (1≤ci, j≤n21 \le c_{i,\,j} \le n^2): the jj-th integer in the ii-th line is the color of the tile in the cell (i, j)(i,\,j).

第一行包含两个整数 nn 和 qq(1≤n≤15001 \le n \le 1500,1≤q≤101 \le q \le 10)—— 分别表示方阵的大小以及子方阵中允许的不同颜色数量上限。

接下来的 nn 行,每行包含 nn 个整数 ci, jc_{i,\,j}(1≤ci, j≤n21 \le c_{i,\,j} \le n^2):其中第 ii 行的第 jj 个整数表示位于单元格 (i, j)(i,\,j) 处瓷砖的颜色。

输出格式

For each kk from 11 to nn print a single integer — the number of subsquares of size k×kk \times k with no more than qq different colors.

对于每个从 11 到 nn 的 kk,输出一个整数——即大小为 k×kk \times k 且包含至多 qq 种不同颜色的子正方形的个数。

输入输出样例

  • 输入#1

    3 4
    1 2 3
    4 5 6
    7 8 9

    输出#1

    9
    4
    0
  • 输入#2

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

    输出#2

    16
    9
    4
    0

说明/提示

In the first example all colors are distinct. Kostya doesn't want the subsquare have more than 44 colors, so he can buy any subsquare of size 1×11 \times 1 or 2×22 \times 2, but he can't buy a subsquare of size 3×33 \times 3.

In the second example there are colors that appear multiple times. Because q=8q = 8, Kostya can buy any subsquare of size 1×11 \times 1 and 2×22 \times 2, and any subsquare 3×33 \times 3, because of such subsquare has 77 different colors. He can't buy the whole stand 4×44 \times 4, because there are 99 colors.

在第一个例子中,所有颜色均不相同。科斯佳不希望子方块包含超过 44 种颜色,因此他可以购买任意 1×11 \times 1 或 2×22 \times 2 的子方块,但不能购买 3×33 \times 3 的子方块。

在第二个例子中,存在重复出现的颜色。由于 q=8q = 8,科斯佳可以购买任意 1×11 \times 1 和 2×22 \times 2 的子方块,以及任意 3×33 \times 3 的子方块(因为这样的子方块仅包含 77 种不同颜色)。但他不能购买整个 4×44 \times 4 展台,因为其中共有 99 种颜色。

输入解题思路,AI测评打分。不知道怎么写?

首页