Marcin and Training Camp

https://codeforces.com/contest/1230/problem/D

Ideas: Find two of the same will certainly be, so to meet the situation, then must contain all relationships. If x | y = x, then x contains y.

#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<stack>
#include<cmath>
#include<iostream>
#include<set>
#define ll long long
#define lowbit(x) x&(-x)
using namespace std;
struct point 
{
    ll x;
    ll y;
}a[10000];
map<ll,int> mp;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i].x);
        mp[a[i].x]++;
    }
    for(int i=1;i<=n;i++)
    scanf("%lld",&a[i].y);
    ll ans=0;
    set<int> ss;
    for(map<ll,int>::iterator t=mp.begin();t!=mp.end();t++)
    {
        if(t->second>=2)
        {
            for(int i=1;i<=n;i++)
            {
                if((t->first|a[i].x)==t->first)
                ss.insert(i);
            }
        }
    }
    for(set<int>::iterator t=ss.begin();t!=ss.end();t++)
    {
        //printf("%d\n",*t);
        int o= (*t);
        ans+=a[o].y;
    }
    printf("%lld\n",ans);
}

 

Guess you like

Origin www.cnblogs.com/2462478392Lee/p/11580927.html