Advertisement
Saleh127

Light OJ 1224 / Hashing - GP Hashtable

Jan 16th, 2023 (edited)
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. /***
  2.  created: 2022-12-09-21.58.50
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10. template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
  11. #define ll long long
  12. #define all(we) we.begin(),we.end()
  13. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  14. #define nl '\n'
  15. #define ull unsigned long long
  16.  
  17. struct custom_hash {
  18.   static uint64_t splitmix64(uint64_t x) {
  19.     x += 0x9e3779b97f4a7c15;
  20.     x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
  21.     x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
  22.     return x ^ (x >> 31);
  23.   }
  24.   size_t operator()(uint64_t x) const {
  25.     static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  26.     return splitmix64(x + FIXED_RANDOM);
  27.   }
  28. };
  29.  
  30. gp_hash_table<ll, ll, custom_hash> x;
  31.  
  32. int main()
  33. {
  34.     ios_base::sync_with_stdio(0);
  35.     cin.tie(0);
  36.     cout.tie(0);
  37.  
  38.  
  39.     test
  40.     {
  41.         x.clear();
  42.  
  43.         ll n,m,i,j,k,l,ans=0;
  44.  
  45.         string a;
  46.  
  47.         cin>>n;
  48.  
  49.         for(i=0;i<n;i++)
  50.         {
  51.             cin>>a;
  52.             ull h=0;
  53.             for(j=0;j<a.size();j++)
  54.             {
  55.                 h=h*149 + a[j];
  56.  
  57.                 x[h]++;
  58.  
  59.                 ans=max(ans,x[h]*(j+1));
  60.             }
  61.         }
  62.         cout<<"Case "<<cs<<": "<<ans<<nl;
  63.     }
  64.  
  65.     return 0;
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement