Advertisement
abdelrahman_orief

Untitled

May 9th, 2020
1,627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3. #define modulo 1000000007
  4. #define int long long
  5. #pragma GCC optimize("-Ofast")
  6. #define float double
  7. #define PI 3.141592653589793238462643383279502884
  8. #define sinDegrees(x) sin((x) * PI / 180.0)
  9. #define tanDegrees(x) tan((x) * PI / 180.0)
  10. #define atanDegrees(x) atan(x)* 180.0 / PI
  11.  
  12. using namespace std;
  13.  
  14. int fact(int n) {
  15.    if (n == 0 || n == 1)
  16.       return 1;
  17.    else
  18.       return n * fact(n - 1);
  19. }
  20.  
  21. int32_t main()
  22. {
  23.     ios_base::sync_with_stdio(false);
  24.     cin.tie(0);
  25.     cout.tie(0);
  26.  
  27.     int n;
  28.     cin>>n;
  29.     map<int, int> fast;
  30.     for (int i=0;i<n;i++)
  31.     {
  32.         string s;
  33.         cin>>s;
  34.         int arr[26]={0};
  35.         for (int j=0;j<s.size();j++)
  36.         {
  37.             arr[s[j]-'a']+=1;
  38.         }
  39.         int a=0;
  40.         for (int j=0;j<26;j++)
  41.         {
  42.             if (arr[j]%2)
  43.                 a+=(1<<j);
  44.         }
  45.         fast[a]++;
  46.     }
  47.     int finale=0;
  48.     for (auto it=fast.begin();it!=fast.end();it++)
  49.     {
  50.         int num=it->first;
  51.         int current=it->second;
  52.         int sze=0;
  53.         for (int j=0;j<26;j++)
  54.         {
  55.             int cpy=num;
  56.             int power = 1<<j;
  57.             if ((cpy & power))
  58.                 cpy-=power;
  59.             else
  60.                 cpy+=power;
  61.             auto fd = fast.find(cpy);
  62.             if (fd!=fast.end())
  63.                 sze+=fd->second;
  64.         }
  65.         finale+=current*sze;
  66.         if (current>1)
  67.             finale+=fact(current) / (fact(2) * fact(current-2));
  68.         it->second = 0;
  69.  
  70.     }
  71.     cout<<finale;
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement