Ankit_132

C

Nov 3rd, 2023
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll long long
  7. #define ss second
  8. #define pb push_back
  9.  
  10. int main()
  11. {
  12. int n;
  13. cin>>n;
  14.  
  15. vector<string> v(n);
  16. for(auto &e: v) cin>>e;
  17.  
  18. ll int ans = 0;
  19.  
  20. vector<map<int, int>> mp(6);
  21.  
  22. vector<pair<int, string>> vs;
  23. for(auto e: v) vs.pb({e.size(), e});
  24.  
  25. sort(vs.begin(), vs.end());
  26. v.clear();
  27. for(auto e: vs) v.pb(e.ss);
  28.  
  29. for(auto s: v)
  30. {
  31. int tot = 0;
  32.  
  33. for(auto d: s)
  34. tot += (d - '0');
  35.  
  36. int a=0, b=0;
  37.  
  38. for(int len=s.size()+2-s.size()%2; len<=10; len+=2)
  39. {
  40. if(len > 2*s.size()) break;
  41.  
  42. a=0, b=0;
  43.  
  44. for(int i=0; i<s.size()-len/2; i++)
  45. {
  46. a += s[i]-'0';
  47. b += s[s.size()-i-1]-'0';
  48. }
  49.  
  50. ans += mp[len-s.size()][tot-2*a];
  51. ans += mp[len-s.size()][tot-2*b];
  52. }
  53.  
  54. mp[s.size()][tot]++;
  55. ans++;
  56. }
  57.  
  58. cout<<ans<<"\n";
  59. }
Advertisement
Add Comment
Please, Sign In to add comment