Ankit_132

NASA

Jun 7th, 2023
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8. #define ff     first
  9. #define ss     second
  10. #define pb     push_back
  11.  
  12.  
  13. int main()
  14. {
  15.     vector<int> pal;
  16.     pal.pb(0);
  17.     string s;
  18.  
  19.     for(int i=1; i<(1<<15); i++)
  20.     {
  21.         s = to_string(i);
  22.  
  23.         int f = 1;
  24.         for(int j=0, k=s.size()-1; j<k; j++, k--)
  25.             f &= s[j]==s[k];
  26.  
  27.         if(f)       pal.pb(i);
  28.     }
  29.    
  30.     _test
  31.     {
  32.         int n;
  33.         cin>>n;
  34.  
  35.         vector<int> a(n);
  36.         for(auto &e: a)
  37.             cin>>e;
  38.  
  39.         unordered_map<int, int> cnt;
  40.  
  41.         for(auto e: a)      cnt[e]++;
  42.  
  43.         ll int ans = 0;
  44.  
  45.         for(auto e: a)
  46.         {
  47.             for(auto p: pal)
  48.                 ans += cnt[(p^e)];
  49.  
  50.             cnt[e]--;
  51.         }
  52.  
  53.         cout<<ans<<"\n";
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment