B. Hyperset

194 篇文章 1 订阅
9 篇文章 0 订阅

链接:https://codeforces.com/contest/1287/problem/B

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.

uploading.4e448015.gif正在上传…重新上传取消

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.

Input

The first line of each test contains two integers nn and kk (1≤n≤15001≤n≤1500, 1≤k≤301≤k≤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.

Output

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

Examples

input

Copy

3 3
SET
ETS
TSE

output

Copy

1

input

Copy

3 4
SETE
ETSE
TSES

output

Copy

0

input

Copy

5 4
SETT
TEST
EEET
ESTE
STES

output

Copy

2

Note

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

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

代码

 

#include<bits/stdc++.h>
using namespace std;
long long n,t,s,k,ans;
string x[1501];
map<string,long long>m;
int main()
{
	scanf("%lld %lld\n",&n,&k);
	s=0;
	ans=0;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
		m[x[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			string y;
			s=0;
			//cout<<x[i][k];
			for(int l=0;l<k;l++)
			{
				if(x[i][l]==x[j][l])
				{
					y+=x[i][l];
				}
				else
				{
					if(x[i][l]=='S')
					{
						if(x[j][l]=='E')
						y+='T';
						else
						y+='E';
					}
					else if(x[i][l]=='T')
					{
						if(x[j][l]=='E')
						y+='S';
						else
						y+='E';
					}
					else
					{
						if(x[j][l]=='S')
						y+='T';
						else
						y+='S';
					}
				}
			}
			//y[k]='\n';
			s=m[y];
			//cout<<m[x[i]]<<m[y]<<endl;
			//cout<<x[i]<<" "<<y;
			if(y==x[i])
			s--;
			if(y==x[j])
			s--;
			ans+=s;
		}
	}
	cout<<ans/3<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值