Advertisement
Ritam_C

codechef TEAMNAME

Feb 6th, 2021
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long int
  4. #define ld long double
  5. #define pb push_back
  6. #define p_b pop_back
  7. #define si stack<int>
  8. #define sll stack<ll>
  9. #define sc stack<char>
  10. #define vi vector<int>
  11. #define vll vector<ll>
  12. #define mii map<int, int>
  13. #define msi map<string, int>
  14. #define mci map<char, int>
  15. #define qc queue<char>
  16. #define qi queue<int>
  17. #define qll queue<ll>
  18. using namespace std;
  19.  
  20. int main(){
  21.     ios_base::sync_with_stdio(false);
  22.     cin.tie(NULL);
  23.     int t;
  24.     cin >> t;
  25.     while(t--){
  26.         int n;
  27.         ld count = 0;
  28.         cin >> n;
  29.         msi r;
  30.         map<char, vector<string>> s;
  31.  
  32.         for(int i = 0; i < n; i++){
  33.             string f;
  34.             cin >> f;
  35.             s[f[0]].pb(f.substr(1, f.length()-1));
  36.         }
  37.  
  38.         for(auto i = s.begin(); i != s.end(); i++){
  39.             set<string> m;
  40.             for(auto j = i; j != s.end(); j++){
  41.                 for(int p = 0; p < (i->second).size(); p++){
  42.                     m.insert((i->second)[p]);
  43.                 }
  44.                 for(int p = 0; p < (j->second).size(); p++){
  45.                     m.insert((j->second)[p]);
  46.                 }
  47.  
  48.                 ld tmp = m.size();
  49.                 count += (tmp-(i->second).size())*(tmp-(j->second).size());
  50.             }
  51.         }
  52.         cout << fixed << setprecision(0) << count*2 << "\n";
  53.     }
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement