CF1735D.Meta-set

传统题 时间 4000 ms 内存 256 MiB 10 尝试 1 已通过 1 标签

Meta-set

CF1735D · Meta-set

  • 难度:1700
  • 标签:brute force、combinatorics、data structures、hashing、math
  • 链接:https://codeforces.com/problemset/problem/1735/D
  • 时间限制:4 seconds 内存限制:256 megabytes
  • 出现位置:Day21-字符串综合-hash-二分-构造/选做

英文原题面

Statement

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?

Input

The first line of the input contains two integers nn and kk (1n1031 \le n \le 10^3, 1k201 \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} (0ci,j20 \le c_{i, j} \le 2) — card features. It is guaranteed that all cards are distinct.

Output

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

样例 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

输出:

3

样例 3

输入:

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

输出:

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

输出:

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.

在线编程 IDE

建议全屏模式获得最佳体验