题意:
给你
n
n
n个长度为
3
3
3的串,串的每个字母都在
a
−
z
a-z
a−z范围内,定义一个串合法当且仅当这个串中含有至少一个元音字母。现在他忘记了元音字母都有那几个,显然有
2
24
2^{24}
224种情况,现在需要对每种情况求一个符合条件的串的个数的平方,再将所有情况的答案异或起来。
n
≤
1
e
4
n\le1e4
n≤1e4
思路:
首先我们需要枚举
2
24
2^{24}
224种情况,如果我们再枚举
n
n
n个串判断的话,复杂度显然是不能接受的,所以我们需要预处理出所需要的信息。
将
24
24
24个串状压成一个
01
01
01串,
1
1
1代表这个位置是元音字母。假设我们枚举的当前情况为
n
o
w
now
now,考虑如果是要求串内每个字母都是元音字母的话,那么我们对每个串去重后状压成二进制,当前串合法的话当且仅当他是
n
o
w
now
now的一个子集,那么我们处理出所有子集信息,答案就是
c
n
t
[
n
o
w
]
∗
c
n
t
[
n
o
w
]
cnt[now]*cnt[now]
cnt[now]∗cnt[now]了。但是这个题是有一个是元音字母就符合要求,我们将串的每个字母拿出来之后给
a
[
1
<
<
i
]
+
+
a[1<<i]++
a[1<<i]++,最终算的答案一定是有重复的,比如当前串是
a
b
c
abc
abc,我们将
a
[
0
]
+
+
,
a
[
2
]
+
+
,
a
[
4
]
+
+
a[0]++,a[2]++,a[4]++
a[0]++,a[2]++,a[4]++,
n
o
w
=
a
b
c
now=abc
now=abc,那么这个串被重复算了三次,明显多了两次,所以我们需要容斥一下。
我们发现如果串去重后长度为
1
1
1,那么直接加上就好。如果串去重后长度为
2
2
2,那么将每个字母都加
1
1
1,让后将两个字母组合的减去
1
1
1即可。如果长度为
3
3
3,那么单个组合都加
1
1
1,两个的组合减
1
1
1,三个的组合加
1
1
1。所以就利用容斥求一下就好啦。
// Problem: E. Vowels
// Contest: Codeforces - Codeforces Round #225 (Div. 1)
// URL: https://codeforces.com/contest/383/problem/E
// Memory Limit: 256 MB
// Time Limit: 4000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;
//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;
int n;
char s[10];
int a[1<<25],p[20];
LL ans=0;
void dfs(int u,int now) {
if(u==24) {
ans^=1ll*a[now]*a[now];
return;
}
dfs(u+1,now+(1<<u));
dfs(u+1,now);
}
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
scanf("%d",&n);
for(int i=1;i<=n;i++) {
scanf("%s",s+1);
int now=0;
int cnt=0;
for(int i=1;i<=3;i++) {
if(now&(1<<(s[i]-'a'))) continue;
a[1<<(s[i]-'a')]++;
p[++cnt]=1<<(s[i]-'a');
now|=(1<<(s[i]-'a'));
}
if(cnt==2) a[p[1]+p[2]]--;
if(cnt==3) {
a[p[1]+p[2]]--;
a[p[1]+p[3]]--;
a[p[2]+p[3]]--;
a[p[1]+p[2]+p[3]]++;
}
}
for(int i=0;i<24;i++)
for(int j=0;j<1<<24;j++)
if(j>>i&1)
a[j]+=a[j^(1<<i)];
dfs(0,0);
cout<<ans<<endl;
return 0;
}
/*
*/