Advertisement
shahil_005

MAGFACT_t_cpp

Feb 22nd, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //----------------------------------- DEBUG -----------------------------------
  5. #define sim template < class c
  6. #define ris return * this
  7. #define dor > debug & operator <<
  8. #define eni(x) sim > typename \
  9. enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
  10. sim > struct rge { c b, e; };
  11. sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
  12. sim > auto dud(c* x) -> decltype(cerr << *x, 0);
  13. sim > char dud(...);
  14. struct debug {
  15. #ifdef LOCAL
  16. ~debug() { cerr << endl; }
  17. eni(!=) cerr << boolalpha << i; ris; }
  18. eni(==) ris << range(begin(i), end(i)); }
  19. sim, class b dor(pair < b, c > d) {
  20.   ris << "(" << d.first << ", " << d.second << ")";
  21. }
  22. sim dor(rge<c> d) {
  23.   *this << "[";
  24.   for (auto it = d.b; it != d.e; ++it)
  25.     *this << ", " + 2 * (it == d.b) << *it;
  26.   ris << "]";
  27. }
  28. #else
  29. sim dor(const c&) { ris; }
  30. #endif
  31. };
  32. #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  33. // debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
  34.  
  35. //----------------------------------- END DEBUG --------------------------------
  36.  
  37. mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  38.  
  39. #define trav(a,x) for (auto& a : x)
  40. #define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
  41.  
  42. //----------------------------------- DEFINES -----------------------------------
  43.  
  44. #define sz(x) (int)(x).size()
  45. #define mp make_pair
  46. #define eb emplace_back
  47. #define pb push_back
  48. #define lb lower_bound
  49. #define ub upper_bound
  50. #define all(x) x.begin(), x.end()
  51. #define rall(x) x.rbegin(), x.rend()
  52. #define ins insert
  53. #define nl '\n'
  54.  
  55. //----------------------------------- END DEFINES --------------------------------
  56.  
  57. //-------------------------- CUSTOM UNORDERED MAP HASH ---------------------------
  58.  
  59. struct custom_hash{
  60.     static uint64_t splitmix64(uint64_t x){
  61.         x += 0x9e3779b97f4a7c15;
  62.         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
  63.         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
  64.         return x ^ (x >> 31);
  65.     }
  66.     size_t operator()(uint64_t a) const {
  67.         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  68.         return splitmix64(a + FIXED_RANDOM);
  69.     }
  70.     template<class T> size_t operator()(T a) const {
  71.         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  72.         hash<T> x;
  73.         return splitmix64(x(a) + FIXED_RANDOM);
  74.     }
  75.     template<class T, class H> size_t operator()(pair<T, H> a) const {
  76.         static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
  77.         hash<T> x;
  78.         hash<H> y;
  79.         return splitmix64(x(a.first) * 37 + y(a.second) + FIXED_RANDOM);
  80.     }
  81. };
  82. template<class T, class H>using umap=unordered_map<T,H,custom_hash>;
  83.  
  84. //----------------------- CUSTOM UNORDERED MAP HASH END--------------------------
  85.  
  86. void run_cases() {
  87.     int n;
  88.     cin >> n;
  89.     vector<vector<int64_t>> cache(300100);
  90.     int64_t ans = 0;
  91.     while(n--) {
  92.         int64_t score = 0;
  93.         string s;
  94.         cin >> s;
  95.         int len = s.length();
  96.         for(auto u: s) {
  97.             score += (u - 'a' + 1);
  98.         }
  99.         if(!cache[len].empty()) {
  100.             ans += abs(cache[len].back() - score);
  101.             cache[len].pop_back();
  102.         }
  103.         else {
  104.  
  105.             cache[len].push_back(score);
  106.         }
  107.     }
  108.     cout << ans << nl;
  109. }
  110.  
  111. int main() {
  112.     ios_base::sync_with_stdio(0); cin.tie(nullptr);
  113.  
  114.     int tests = 1;
  115.     // cin >> tests;
  116.  
  117.     for(int test = 1;test <= tests;test++) {
  118.         run_cases();
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement