fork(2) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #include <iomanip>
  13. #define dibs reserve
  14. #define OVER9000 1234567890
  15. #define patkan 9
  16. #define tisic 47
  17. #define soclose 10e-7
  18. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  19. #define chocolate win
  20. #define ff first
  21. #define ss second
  22. #define abs(x) ((x < 0)?-(x):(x))
  23. // mylittlepony
  24. using namespace std;
  25.  
  26. int main() {
  27. cin.sync_with_stdio(0);
  28. int N;
  29. cin >> N;
  30. string s;
  31. map< vector<long long>,int> M;
  32. long long mod =1000000009, p =999983;
  33. for(int i =0; i < N; i++) {
  34. cin >> s;
  35. vector< vector<int> > V(26);
  36. for(int j =0; j < s.length(); j++) V[s[j]-'a'].push_back(j);
  37. sort(V.begin(),V.end());
  38. vector<long long> H(26,0);
  39. for(int j =0; j < 26; j++) ALL_THE(V[j],it) {
  40. H[j] =(H[j]*p+(*it)+1)%mod;
  41. if(H[j] < mod) H[j] +=mod;}
  42. M[H] =M[H]+1;}
  43. long long ans =0;
  44. ALL_THE(M,it) ans +=(long long)(it->ss)*(long long)(it->ss-1)/2;
  45. cout << ans << "\n";
  46. return 0;}
  47.  
  48. // look at my code
  49. // my code is amazing
Success #stdin #stdout 0s 3484KB
stdin
4
your
code
wont
pass
stdout
3