Advertisement
Rishav_hitk_cse

Untitled

Feb 14th, 2021
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. // Maximum satisfaction
  2. #include <bitset>
  3. int Solution::solve(vector<int> &a) {
  4.     const int n = a.size();
  5.     vector<int> bit(31);
  6.     vector<bitset<100001>> st(31);
  7.     for(int i=0;i<n;i++){
  8.         for(int j=0;j<31;j++){
  9.             if(a[i]&(1<<j)){
  10.                 bit[j]++;
  11.                 st[j].set(i);
  12.             }
  13.         }
  14.     }
  15.  
  16.     int ans = 0;
  17.     bitset<100001> curr;
  18.     for(int i=0;i<n;i++) curr.set(i);
  19.     for(int b = 30;b>=0;b--){
  20.         if(bit[b]<4)
  21.             continue;
  22.         auto &now = st[b];
  23.         auto temp = (curr&now);
  24.         int cnt = temp.count();
  25.         if(cnt>=4){
  26.             ans+=(1<<b);
  27.             curr = temp;
  28.         }
  29.     }
  30.     return ans;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement