CF1287B.Hyperset

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.

Polina came up with a new game called "Hyperset". In her game, there are nn cards with kk features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with k=4k = 4.

Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.

Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.

蜜蜂爱丽丝和阿列西娅送给养蜂人波琳娜一款著名的纸牌游戏“Set”作为圣诞礼物。这副牌由若干张卡片组成,每张卡片在四个特征上各不相同,每个特征均有三种可能的取值:图形数量、图形形状、阴影样式和颜色。在该游戏中,某些三张卡片的组合被称为一个“set”(集合)。对于每一个特征(颜色、数量、形状、阴影),这三张卡片在该特征上的取值必须全部相同,或两两互不相同。下图展示了“set”的样例:

波琳娜设计了一款新游戏,名为“Hyperset”。在她的游戏中,共有 nn 张卡片,每张卡片具有 kk 个特征;每个特征有三种可能的取值:“S”、“E”或“T”。原始的“Set”游戏可视为 k=4k = 4 的“Hyperset”。

与原游戏类似,三张卡片构成一个集合,当且仅当对于每一个特征,这三张卡片在该特征上的取值要么全部相同,要么两两互不相同。游戏的目标是计算从中选出三张卡片能构成集合的方案数。

不幸的是,寒假已经结束,波琳娜该返校上学了。请帮助波琳娜计算桌面上这些卡片中能构成集合的三元组个数。

输入格式

The first line of each test contains two integers nn and kk (1≤n≤15001 \le n \le 1500, 1≤k≤301 \le k \le 30) — number of cards and number of features.

Each of the following nn lines contains a card description: a string consisting of kk letters "S", "E", "T". The ii-th character of this string decribes the ii-th feature of that card. All cards are distinct.

每组测试数据的第一行包含两个整数 nn 和 kk(1≤n≤15001 \le n \le 1500,1≤k≤301 \le k \le 30)——分别表示卡片数量和特征数量。

接下来的 nn 行,每行描述一张卡片:一个由 kk 个字母组成的字符串,每个字母为 "S"、"E" 或 "T"。该字符串的第 ii 个字符表示该卡片的第 ii 个特征。所有卡片互不相同。

输出格式

Output a single integer — the number of ways to choose three cards that form a set.

输出一个整数——能够组成一组(set)的三张卡片的选择方式数量。

输入输出样例

  • 输入#1

    3 3
    SET
    ETS
    TSE

    输出#1

    1
  • 输入#2

    3 4
    SETE
    ETSE
    TSES

    输出#2

    0
  • 输入#3

    5 4
    SETT
    TEST
    EEET
    ESTE
    STES

    输出#3

    2

说明/提示

In the third example test, these two triples of cards are sets:

  1. "SETT", "TEST", "EEET"
  2. "TEST", "ESTE", "STES"

在第三个样例测试中,以下两组三张卡片构成“集合”(set):

  1. "SETT", "TEST", "EEET"
  2. "TEST", "ESTE", "STES"

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

首页