Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define endl '\n'
- #define modulo 1000000007
- #define int long long
- #pragma GCC optimize("-Ofast")
- #define float double
- #define PI 3.141592653589793238462643383279502884
- #define sinDegrees(x) sin((x) * PI / 180.0)
- #define tanDegrees(x) tan((x) * PI / 180.0)
- #define atanDegrees(x) atan(x)* 180.0 / PI
- using namespace std;
- int fact(int n) {
- if (n == 0 || n == 1)
- return 1;
- else
- return n * fact(n - 1);
- }
- int32_t main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int n;
- cin>>n;
- map<int, int> fast;
- for (int i=0;i<n;i++)
- {
- string s;
- cin>>s;
- int arr[26]={0};
- for (int j=0;j<s.size();j++)
- {
- arr[s[j]-'a']+=1;
- }
- int a=0;
- for (int j=0;j<26;j++)
- {
- if (arr[j]%2)
- a+=(1<<j);
- }
- fast[a]++;
- }
- int finale=0;
- for (auto it=fast.begin();it!=fast.end();it++)
- {
- int num=it->first;
- int current=it->second;
- int sze=0;
- for (int j=0;j<26;j++)
- {
- int cpy=num;
- int power = 1<<j;
- if ((cpy & power))
- cpy-=power;
- else
- cpy+=power;
- auto fd = fast.find(cpy);
- if (fd!=fast.end())
- sze+=fd->second;
- }
- finale+=current*sze;
- if (current>1)
- finale+=fact(current) / (fact(2) * fact(current-2));
- it->second = 0;
- }
- cout<<finale;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement