Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Maximum satisfaction
- #include <bitset>
- int Solution::solve(vector<int> &a) {
- const int n = a.size();
- vector<int> bit(31);
- vector<bitset<100001>> st(31);
- for(int i=0;i<n;i++){
- for(int j=0;j<31;j++){
- if(a[i]&(1<<j)){
- bit[j]++;
- st[j].set(i);
- }
- }
- }
- int ans = 0;
- bitset<100001> curr;
- for(int i=0;i<n;i++) curr.set(i);
- for(int b = 30;b>=0;b--){
- if(bit[b]<4)
- continue;
- auto &now = st[b];
- auto temp = (curr&now);
- int cnt = temp.count();
- if(cnt>=4){
- ans+=(1<<b);
- curr = temp;
- }
- }
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement