Pentru această operație este nevoie să te autentifici.
Cod sursă (job #800405)
Utilizator |
|
IP | ascuns |
---|---|---|---|
Problemă | Cristela (clasele 9-12) | Compilator | cpp-32 | 0.86 kb |
Rundă | Arhiva de probleme | Status | evaluat |
Dată | 20 dec. 2024 18:05:55 | Scor | 15 |
#include <fstream>
#include<algorithm>
using namespace std;
ifstream cin("cristela.in");
ofstream cout("cristela.out");
int v[1 << 20], dp[1 << 20];
int getPairs(long long n)
{
long long total = n * (n - 1);
int i = 0, j = (1 << 20)-1;
for (; j >= 0; i++, j--)
{
total -= (v[i] * dp[j]);
}
return total / 2;
}
int main()
{
ios::sync_with_stdio(false);
long long n;
int x, m = 0;
string s;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> s;
x = 0;
for (char c: s)
{
x |= (1 << (c - 'a'));
}
v[x]++;
dp[x]++;
}
for (int i = 0; i < 20; i++)
{
for (int mask = 0; mask < (1 << 20); mask++)
{
if (mask & (1 << i))
dp[mask] += dp[mask ^ (1 << i)];
}
}
cout << getPairs(n);
}
/*
abac 000111
dde 011000
bda 001011
faf 100001
111111
*/