Advertisement
Emiliatan

e288

Jul 22nd, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. /* e288             */
  2. /* AC(0.6s, 32.7MB) */
  3. #pragma warning( disable : 4996 )
  4. #include <cstdio>
  5. #include <cstring>
  6. #include <cstdint>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <tuple>
  10. #include <unordered_set>
  11. #define ios_jazz ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
  12.  
  13. using namespace std;
  14.  
  15. constexpr int Dir4[4][2] = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };
  16. constexpr int Dir8[8][2] = { {-1, -1}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 1} };
  17. constexpr double EPS = 1e-9;
  18. const double PI = acos(-1);
  19.  
  20. using int16 = short;
  21. using uint16 = unsigned short;
  22. using uint = unsigned int;
  23. using int64 = long long;
  24. using uint64 = unsigned long long;
  25. using pii = pair<int, int>;
  26.  
  27. /* fast power */
  28. auto pow_fast_2 = [](int64 b) -> int64 { return 1 << b; };
  29.  
  30. template <typename T>
  31. T pow_fast(T x, int64 b) noexcept
  32. {
  33.     T tmp = 1;
  34.     while (b)
  35.     {
  36.         if (b & 0x1) tmp = x * tmp;
  37.         x = x * x;
  38.         b >>= 1;
  39.     }
  40.     return tmp;
  41. }
  42.  
  43. /* Dijoint Set */
  44. constexpr int _MAXN_Dijoint = 10000;
  45. int _Parent[_MAXN_Dijoint], _Rank[_MAXN_Dijoint];
  46. int _Find(int x) noexcept
  47. {
  48.     return (_Parent[x] == x ? x : x = _Find(_Parent[x]));
  49. }
  50. bool _Union(int x, int y) noexcept
  51. {
  52.     x = _Find(x), y = _Find(y);
  53.     if (x == y) return false;
  54.     if (_Rank[x] > _Rank[y]) swap(x, y);
  55.     _Parent[x] = y, _Rank[y] += _Rank[x];
  56.     return true;
  57. }
  58.  
  59. /* exgcd  __X * a + __Y * b = gcd(a, b) */
  60. int64 __X, __Y;
  61. tuple<int64, int64, int64> exgcd(int64 a, int64 b) noexcept
  62. {
  63.     if (b == 0)
  64.     {
  65.         __X = 1;
  66.         __Y = 0;
  67.         return { __X, __Y, a };
  68.     }
  69.     int64 r = get<2>(exgcd(b, a % b));
  70.     int64 tmp = __X;
  71.     __X = __Y;
  72.     __Y = tmp - a / b * __Y;
  73.     return { __X, __Y, r };
  74. }
  75.  
  76. /* main code */
  77. constexpr int MAXN = 500001;
  78. int n, m;
  79. char s[1001], ch;
  80. int64 hash[MAXN], ans;
  81. int64 max;
  82. unordered_multiset<int64> uset;
  83.  
  84. int main()
  85. {
  86.     scanf("%d %d", &m, &n);
  87.     getchar();
  88.  
  89.     ::max = ((int64)1 << m) - 1;
  90.  
  91.     for (int i = 0; i < n; ++i)
  92.     {
  93.         while ((ch = getchar()) && ch != '\n')
  94.         {
  95.             if (ch >= 'A' && ch <= 'Z') ch -= 'A';
  96.             else if (ch >= 'a' && ch <= 'z') ch -= 'a' - 26;
  97.  
  98.             if (m > ch)
  99.                 ::hash[i] |= ((int64)1 << ch);
  100.         }
  101.     }
  102.  
  103.     for (int i = 0; i < n; ++i)
  104.     {
  105.         ans += uset.count(::max - ::hash[i]);
  106.         uset.emplace(::hash[i]);
  107.     }
  108.  
  109.     printf("%lld", ans);
  110.  
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement