CF1735D.Meta-set

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You like the card board game "Set". Each card contains kk features, each of which is equal to a value from the set 0,1,2{0, 1, 2}. The deck contains all possible variants of cards, that is, there are 3k3^k different cards in total.

A feature for three cards is called good if it is the same for these cards or pairwise distinct. Three cards are called a set if all kk features are good for them.

For example, the cards (0,0,0)(0, 0, 0), (0,2,1)(0, 2, 1), and (0,1,2)(0, 1, 2) form a set, but the cards (0,2,2)(0, 2, 2), (2,1,2)(2, 1, 2), and (1,2,0)(1, 2, 0) do not, as, for example, the last feature is not good.

A group of five cards is called a meta-set, if there is strictly more than one set among them. How many meta-sets there are among given nn distinct cards?

你喜欢纸牌游戏“Set”。每张卡片包含 kk 个特征,每个特征的取值均属于集合 {0,1,2}\{0, 1, 2\}。整副牌包含所有可能的卡片组合,即共有 3k3^k 张互不相同的卡片。

对于三张卡片,若某一个特征在这三张卡片上全部相同,或两两互不相同,则称该特征对这三张卡片是“好的”。若三张卡片的所有 kk 个特征均为“好的”,则称这三张卡片构成一个“set”(集合)。

例如,卡片 (0,0,0)(0, 0, 0)、(0,2,1)(0, 2, 1) 和 (0,1,2)(0, 1, 2) 构成一个 set;但卡片 (0,2,2)(0, 2, 2)、(2,1,2)(2, 1, 2) 和 (1,2,0)(1, 2, 0) 不构成 set,因为例如第三个特征(即最后一位)不是“好的”。

若一组五张卡片中严格包含多于一个 set,则称该组为一个“meta-set”(元集合)。给定 nn 张互不相同的卡片,其中共有多少个 meta-set?

输入格式

The first line of the input contains two integers nn and kk (1≤n≤1031 \le n \le 10^3, 1≤k≤201 \le k \le 20) — the number of cards on a table and the number of card features. The description of the cards follows in the next nn lines.

Each line describing a card contains kk integers ci,1,ci,2,…,ci,kc_{i, 1}, c_{i, 2}, \ldots, c_{i, k} (0≤ci,j≤20 \le c_{i, j} \le 2) — card features. It is guaranteed that all cards are distinct.

输入的第一行包含两个整数 nn 和 kk(1≤n≤1031 \le n \le 10^3,1≤k≤201 \le k \le 20)—— 分别表示桌面上的卡片数量和每张卡片的特征数量。接下来的 nn 行描述这些卡片。

每行描述一张卡片,包含 kk 个整数 ci,1,ci,2,…,ci,kc_{i, 1}, c_{i, 2}, \ldots, c_{i, k}(0≤ci,j≤20 \le c_{i, j} \le 2)—— 表示该卡片的各个特征。保证所有卡片互不相同。

输出格式

Output one integer — the number of meta-sets.

输出一个整数——元集的数量。

输入输出样例

  • 输入#1

    8 4
    0 0 0 0
    0 0 0 1
    0 0 0 2
    0 0 1 0
    0 0 2 0
    0 1 0 0
    1 0 0 0
    2 2 0 0

    输出#1

    1
  • 输入#2

    7 4
    0 0 0 0
    0 0 0 1
    0 0 0 2
    0 0 1 0
    0 0 2 0
    0 1 0 0
    0 2 0 0

    输出#2

    3
  • 输入#3

    9 2
    0 0
    0 1
    0 2
    1 0
    1 1
    1 2
    2 0
    2 1
    2 2

    输出#3

    54
  • 输入#4

    20 4
    0 2 0 0
    0 2 2 2
    0 2 2 1
    0 2 0 1
    1 2 2 0
    1 2 1 0
    1 2 2 1
    1 2 0 1
    1 1 2 2
    1 1 0 2
    1 1 2 1
    1 1 1 1
    2 1 2 0
    2 1 1 2
    2 1 2 1
    2 1 1 1
    0 1 1 2
    0 0 1 0
    2 2 0 0
    2 0 0 2

    输出#4

    0

说明/提示

Let's draw the cards indicating the first four features. The first feature will indicate the number of objects on a card: 11, 22, 33. The second one is the color: red, green, purple. The third is the shape: oval, diamond, squiggle. The fourth is filling: open, striped, solid.

You can see the first three tests below. For the first two tests, the meta-sets are highlighted.

In the first test, the only meta-set is the five cards (0000, 0001, 0002, 0010, 0020)(0000,\ 0001,\ 0002,\ 0010,\ 0020). The sets in it are the triples (0000, 0001, 0002)(0000,\ 0001,\ 0002) and (0000, 0010, 0020)(0000,\ 0010,\ 0020). Also, a set is the triple (0100, 1000, 2200)(0100,\ 1000,\ 2200) which does not belong to any meta-set.

In the second test, the following groups of five cards are meta-sets: (0000, 0001, 0002, 0010, 0020)(0000,\ 0001,\ 0002,\ 0010,\ 0020), (0000, 0001, 0002, 0100, 0200)(0000,\ 0001,\ 0002,\ 0100,\ 0200), (0000, 0010, 0020, 0100, 0200)(0000,\ 0010,\ 0020,\ 0100,\ 0200).

In there third test, there are 5454 meta-sets.

我们来绘制表示前四个特征的卡片。第一个特征表示卡片上物体的数量:11、22、33;第二个特征表示颜色:红色、绿色、紫色;第三个特征表示形状:椭圆形、菱形、S形(squiggle);第四个特征表示填充方式:空心、条纹、实心。

下方展示了前三组测试样例。对于前两个测试,其中的“元组集”(meta-sets)已被高亮标出。

在第一个测试中,唯一的元组集是五张卡片 (0000, 0001, 0002, 0010, 0020)(0000,\ 0001,\ 0002,\ 0010,\ 0020)。该元组集中包含的集合(sets)为三元组 (0000, 0001, 0002)(0000,\ 0001,\ 0002) 和 (0000, 0010, 0020)(0000,\ 0010,\ 0020)。此外,三元组 (0100, 1000, 2200)(0100,\ 1000,\ 2200) 也是一个集合,但它不属于任何元组集。

在第二个测试中,以下五张卡片组成的组均为元组集:(0000, 0001, 0002, 0010, 0020)(0000,\ 0001,\ 0002,\ 0010,\ 0020)、(0000, 0001, 0002, 0100, 0200)(0000,\ 0001,\ 0002,\ 0100,\ 0200)、(0000, 0010, 0020, 0100, 0200)(0000,\ 0010,\ 0020,\ 0100,\ 0200)。

在第三个测试中,共有 5454 个元组集。

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

首页